我试图了解使用功能性接口优于常规接口的优势。因此,假设我有此代码
package Java8;
public class FunctionalCheck implements InterfaceOne{
public static void main(String[] args) {
InterfaceTwo interfaceTwo = (int n1,int n2) -> System.out.println(n1*n2);
interfaceTwo.multiply(10, 20);
FunctionalCheck functionalCheck= new FunctionalCheck();
functionalCheck.multiply(10,50);
}
@Override
public void multiply(int n1, int n2) {
System.out.println(n1*n2);
}
}
interface InterfaceOne{
public void multiply(int n1,int n2);
}
interface InterfaceTwo{
abstract public void multiply(int n1,int n2);
}
那么使用功能接口方法的优点是什么?
InterfaceTwo interfaceTwo = (int n1,int n2) -> System.out.println(n1*n2);
interfaceTwo.multiply(10, 20);
使用常规接口可以执行相同操作时。预先感谢