這個lambda表達式適用於具有兩個操作數(a和b)的數學運算。帶有其他操作數的Java lambda表達式
public class Math {
interface IntegerMath {
int operation(int a, int b);
}
private static int apply(int a, int b, IntegerMath op) {
return op.operation(a, b);
}
public static void main(String... args) {
IntegerMath addition = (a, b) -> a + b;
IntegerMath subtraction = (a, b) -> a - b;
System.out.println("40 + 2 = " + apply(40, 2, addition));
System.out.println("20 - 10 = " + apply(20, 10, subtraction));
}
}
你怎麼能增強這種類例如
IntergerMath square = (a) -> a * a;
可能一元操作?