手写函数表达式,实现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);
	}

  

 

posted @ 2022-01-29 14:35  红尘沙漏  阅读(38)  评论(0编辑  收藏  举报