1、Predicate是参数的布尔函数。该接口提供了许多默认函数,以组合复杂的逻辑操作(和,非)。

Predicate predicate = (s) -> s.length() > 0;
 
predicate.test("foo");              // true
predicate.negate().test("foo");     // false
 
Predicate nonNull = Objects::nonNull;
Predicate isNull = Objects::isNull;
 
Predicate isEmpty = String::isEmpty;
Predicate isNotEmpty = isEmpty.negate();

2、Function接收参数以产生结果。默认方法可用于多种方法构成的方法链。

Function toInteger = Integer::valueOf;
Function backToString = toInteger.andThen(String::valueOf);
 
backToString.apply("123");     // "123"

3、Supplier根据给定的类属性生成对象,Supplier不支持输入参数。

Supplier personSupplier = Person::new;
personSupplier.get();   // new Person
本文转载于:https://www.yisu.com/zixun/695981.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。