表达形式
(parameters) -> expression
(parameters) -> {statement;}
形式一:没有参数
() -> System.out.println("Helo World")
形式二:只有一个参数
name -> System.out.println("Hello World from "+ name +" !");
形式三:没有参数,逻辑复杂
()-> {
System.out.println("Hello");
System.out.println("World");
}
形式四:包含两个参数的方法
BinaryOperator<Long> functionAdd = (x,y) -> x + y;
Long result = functionAdd.apply(1L, 2L);
形式五:对参数显示声明
BinaryOperator<Long> functionAdd = (Long x,Long y) -> x + y;
Long result = functionAdd.apply(1L, 2L);
函数式接口
接口中只有一个抽象方法
Java8的函数式接口注解: @FunctionInterface
函数式接口的抽象方法签名:函数描述符