1.常用函数是接口:
(1)Function<T, R> => R apply(T t) ———— 接受一个T类型的参数,返回R类型结果。
Function<Integer, String> function1 = (x) -> "result: " + x;
function1.apply(6);
(2)Consumer<T> => void accept(T t) ———— 接受一个T类型的参数,无返回。
Consumer<String> consumer = (x) -> System.out.println("consumer: " + x);
consumer.accept("Hello");
(3)Predicate<T> => boolean test(T t) ———— 接受一个T类型的参数,返回布尔值。
Predicate<String> predicate = (x) -> x.length() > 0;
predicate.test("String");
(4)Supplier<T> => T get() ———— 无输入参数,返回T类型的一个结果。
Supplier<String> supplier = () -> "Test supplier";
supplier.get();