Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

        
AI编程,程序员挑战年入30~100万高级指南 - 职业规划
SpringBoot+SpringSecurity+Vue权限系统高级实战课程        

IDEA永久激活

Java微信小程序电商实战课程(SpringBoot+VUe)

     

AI人工智能学习大礼包

     

PyCharm永久激活

66套java实战课程无套路领取

     

Cursor+Claude AI编程 1天快速上手视频教程

     
当前位置: 主页 > Java文档 > Java基础相关 >

Java 8 中的炫酷特性和 Java 9 中的新特性 PDF 下载


时间:2020-07-18 19:06来源:http://www.java1234.com 作者:小锋  侵权举报
Java 8 中的炫酷特性和 Java 9 中的新特性 PDF 下载
失效链接处理
Java 8 中的炫酷特性和 Java 9 中的新特性 PDF 下载

 
本站整理下载:
提取码:xueb 
 
 
相关截图:
 
主要内容:

从行为进行抽象
“命题: 如何从人员信息的集合里删除所有超过18岁的人?” 
Collection<Person> peoples = ...;
for (Person p : peoples){
if (p.getAge() > 18)
?? How do we remove this person ???
}
Collection<Person> peoples = ...;
Iterator<Person> it = peoples.iterator();
while (it.hasNext()) {
Person p = it.next();
if (p.getAge() > 18)
it.remove();
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 
进一步抽象
interface Predicate<T> { 
boolean test(T t);
}
class Collections {
public static<T> 
void removeMatching(Collection<T> coll, 
Predicate<T> pred) { 
...
} }
The API Designer
Could create methods in the 
collection
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 
Collection<Person> peoples = ...;
Collections.removeMatching(peoples, 
new Predicate<Person>() {
public boolean test(Person p) {
return p.getAge() > 18; } } });
修改后的实现 But the code to use the new 
method would be bloated
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 
使用Java SE 8
• Interface Collection<E> – removeIf(Predicate<? super E> filter)
10
// 简化版
Collection<Person> peoples = ...;
peoples.removeIf(p -> p.getAge() > 18);

 

------分隔线----------------------------


锋哥推荐