函数式接口学习

  1. 四大函数式接口

    1. 消费型接口 :

           Consumer<T>    void accept(T t)
      
    2. 供给型接口:

          Supplier<T>    T get();
      
    3. 函数型接口:
      Function<T,R> R apply(T t);

    4. 断言型接口:
      Predicate boolean test(T t);

拓展:

  1. BiFunction<T,U,R> R apply(T t, U u);

  2. UnaryOperator (Function 子接口) T apply(T t);

  3. BinaryOperator (Function 子接口 T apply(T t1, T t2);

4, BiConsumer<T,U> void accept(T t, U u);

  1. ToIntFunction 计算int值的函数 返回int

  2. ToDoubleFunction 计算double值的函数 返回double

  3. ToLongFunction 计算long值的函数 返回long

  4. LongFunction 参数为long类型的函数 返回 R

  5. IntFunction 参数为int类型的函数 返回 R

  6. DoubleFunction 参数为double类型的函数 返回 R

其他常见的函数式接口:
public interface Runnable { void run(); }

public interface Callable { V call() throws Exception; }

public interface Comparator { int compare(T o1, T o2); boolean equals(Object obj); }

原文地址:https://www.cnblogs.com/harper2/p/14165695.html