1、Predicate是布尔型函数,只有一个输入参数。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接口产生给定类型的结果。不像Function,Supplier没有输入参数。

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