内置的四大函数接口及使用?

千锋教育

消费型接口: Consumer< T> void accept(T t)有参数,无返回值的抽象方法;



供给型接口: Supplier < T> T get() 无参有返回值的抽象方法;

以stream().collect(Collector<? super T, A, R> collector)为例: 

比如:



断定型接口:Predicate<T> boolean test(T t):有参,但是返回值类型是固定的boolean

比如: steam().filter()中参数就是Predicate


函数型接口: Function<T,R> R apply(T t)有参有返回值的抽象方法;

比如: steam().map() 中参数就是Function<? super T, ? extends R>;reduce()中参数BinaryOperator<T> (ps: BinaryOperator<T> extends BiFunction<T,T,T>)