欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Lambda且接口 Lambdajava8 

程序员文章站 2022-04-17 23:18:22
...

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 java8