interface MathOperation {
int execute(int a, int b);
}
public int calculate(int a, int b, MathOperation op) {
return op.execute(a, b);
}
public static void main(String[] args) {
Lamda lamda = new Lamda();
MathOperation addition = (a, b) -> (a + b);
MathOperation substract = (a, b) -> (a - b);
System.out.println(lamda.calculate(4, 5, addition));
System.out.println(lamda.calculate(4, 5, substract));
}
No comments:
Post a Comment