Lambda 表达式需要“函数式接口”的支持
函数式接口:接口中只有一个抽象方法的接口,称为函数式接口。 可以使用注解 @FunctionalInterface 修饰可以检查是否是函数式接口
/* 二、Lambda 表达式需要“函数式接口”的支持
函数式接口:接口中只有一个抽象方法的接口,称为函数式接口。 可以使用注解 @FunctionalInterface 修饰
可以检查是否是函数式接口*/
@Test
public void ceui6() {
Integer operation = operation(100, (x) -> x * x);
System.out.println(operation); // 10000
System.out.println("-------------------------");
Integer operation1 = operation(100, (x) -> x + 200);
System.out.println(operation1);// 300
}
public Integer operation(int a, MyFun mf) {
return mf.getValue(a);
}