Lambda表达式实现的接口不是普通的接口,称为是函数式接口,这种接口只能有一个方法。
如果接口中声明多个抽象方法,就会报错误
The target type of this expression must be a functional interface
示例代码如下:
public class lambdaTest {
@Test
public void test() {
//显示计算结果
display((a,b)->{
return a + b;
},1,2);
}
/**
*
* @param c Lambda表达式
* @param a
* @param b
*/
public static void display(Calc c,int a, int b) {
System.out.println(c.calcInt(a, b));
}
/**
* 函数式接口
* @author busifox
*
*/
public interface Calc {
int calcInt(int a, int b);
}
}