函数式接口

1. @FunctionalInterface函数式接口,一般可以作为方法的参数和返回值类型。
(1)有且只有一个抽象方法的接口,称之为函数式接口
(2)可以包含其他的方法(默认,静态,私有)


2. Runnable
void run()

3. Function<T, R>
R apply(T t);
default <V> Function<V, R> compose(Function<? super V, ? extends T> before);
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after);

4. BiFunction<T, U, R>
R apply(T t, U, u);
default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after);


5. Supplier<T>
T get();

6. Consumer<T>
void accept(T t);
Consumer<T> andThen(Consumer<? super T> after);

7. BiConsumer<T, U>
void accept(T t, U u);
default BiConsumer<T, U> andThen(BiConsumer<? super T, ? super U> after);

8. Predicate<T>
boolean test(T t);
default Predicate<T> and(Predicate<? super T> other);
default Predicate<T> negate();
default Predicate<T> or(Predicate<? super T> other);

9. BiPredicate<T, U>
boolean test(T t, U u);
default BiPredicate<T, U> and(Predicate<? super T, ? super U> other);
default Predicate<T, U> negate();
default Predicate<T, U> or(Predicate<? super T, ? super U> other);

posted @ 2023-03-28 11:11  小路不懂2  阅读(23)  评论(0编辑  收藏  举报