System.out.println("Consumer接口 接收1个参数,0输出");
Consumer<Integer> help = (num) -> System.out.println(num);
help.accept(b);
System.out.println("Supplier接口 接收0个参数,1输出");
Supplier<String> help2 = () -> "abc";
System.out.println(help2.get());
System.out.println("Function接口 接收1个参数,1输出");
Function<Integer,String> help3 = (integer) -> String.valueOf(integer);
System.out.println(help3.apply(3));
System.out.println("Predicate接口 接收1个参数,条件判断返回真伪");
Predicate<String> help4 = (string) -> string.length() > 3;
System.out.println(help4.test("abc"));
System.out.println(help4.test("abcd"));
输出结果:
Consumer接口 接收1个参数,0输出
1
Supplier接口 接收0个参数,1输出
abc
Function接口 接收1个参数,1输出
3
Predicate接口 接收1个参数,条件判断返回真伪
false
true