函数式接口与lambda表达式
函数式接口:只有一个方法的接口
public interface CanAdd {
int add(int a,int b);
}
该接口作为其他方法的入参,实现函数传递
public class Dog {
public static void add(int a,int b,CanAdd c){
System.out.println(c.add(a, b));
}
}
使用lambda传入函数
public static void main(String[] args) {
Dog.add(2,4,(int a,int b)->a+b);
}