一、什么是Lambda表达式 Lambda表达式允许把函数作为一个方法的参数,使代码变得更加简洁紧凑。
二、Lambda表达式语法 表达式的语法:
(parameters
) -> expression
(x
) -> x
* 2
(x
, y)
-> x
- y
三、函数式接口 函数式接口是仅指定一个抽象方法的接口,例如:
interface MathInterface{
int getValue();
}
使用Lambda表达式实现函数式接口的抽象方法:
MathInterface mathInterface
;
mathInterface
= () -> 12;
mathInterfae
.getValue();