手写函数表达式,实现lamda表达式
//函数式接口
package lamdaTest; @FunctionalInterface public interface MyFunction { public Integer getValue(Integer num); }
//具体实现调用
/**
* 执行实现方法
*/
@Test
public void test2() {
Integer num= opertion(3,(x)->x*2);//(x)->x*2 使用lamda表达式实现接口
System.out.println("num======="+num);
}
/**
* 调用接口方法
* @param num
* @param funtion
* @return
*/
public Integer opertion(Integer num,MyFunction funtion) {
return funtion.getValue(num);
}


浙公网安备 33010602011771号