JAVA Lambda表达式的使用
package lambda; public interface Addable { int add(int x,int y); }
package lambda; public class AddableDemo { public static void main(String[] args) { //用匿名内部类方式 useAddable(new Addable() { @Override public int add(int x, int y) { System.out.println(x+"||"+y); return 0; } }); //用Lambda useAddable((int x,int y)->{ System.out.println(x+"||"+y); return 0; }); } public static void useAddable(Addable a){ System.out.println(a.add(1,2)); } }