Supplier: 生产
Supplier s =()->"生产了一个字符串";System.out.println(s.get());
Consumer: 消费
Consumer<String> c =System.out::println;
c.accept("abc");Consumer<String> c2 = s ->System.out.println(newStringBuilder(s).reverse().toString());
c.andThen(c2).accept("abc");
Predicate: 判断
Predicate<Integer> p = i -> i >3;Predicate<Integer> p2 = i -> i <8;System.out.println(p.test(5));// 逻辑判断System.out.println(p.negate().test(5));// 否定System.out.println(p.and(p2).test(5));// 逻辑或System.out.println(p.or(p2).test(5));// 逻辑与
Function: 功能
Function<String,Integer> f =Integer::parseInt;Function<Integer,String> f2 =String::valueOf;System.out.println(f.apply("123"));System.out.println(f.andThen(f2).apply("123"));