interface MathOperation{
int operation(int a,int b);
}
private int operation(int a,int b,MathOperation mathOperation){
return mathOperation.operation(a,b);
}
MathOperation addition = (a, b) -> a + b;
MathOperation subtraction = (a, b) -> a - b;
MathOperation multiplication = (a, b) -> a * b;
MathOperation division = (a, b) -> a / b;
Java8Tester tester = new Java8Tester();
System.out.println("10 + 5 = " + tester.operate(10, 5, addition));
System.out.println("10 - 5 = " + tester.operate(10, 5, subtraction));
System.out.println("10 x 5 = " + tester.operate(10, 5, multiplication));
System.out.println("10 / 5 = " + tester.operate(10, 5, division));
Lambda且接口
最新推荐文章于 2021-05-25 20:24:17 发布