看代码和注释
lombda类似于es6中的写法
package cy.learningInterface;
public class Test{
public static void main(String[] args) {
TestInterface testInterface = new TestInterface() {
@Override
public int test(int a, int b) {
System.out.println("原始写法");
return a + b;
}
};
System.out.println(testInterface.test(10, 20));
TestInterface testInterface2 = (a,b) ->{
System.out.println("lombda简写");
return a + b;
};
int test = testInterface2.test(10, 20);
System.out.println(test);
}
}
package cy.learningInterface;
@FunctionalInterface
public interface TestInterface {
int test(int a,int b);
}