As you all know we engineers works best at nights :) I was studying lambdas at yesterday night and I saw a piece of code like that,
BirdCompare tester = new BirdCompare();
MathOperation addition = (a, b) -> (a + b);
MathOperation subtraction = (int a, int b) -> (a - b);
MathOperation multiplication = (int a, int b) -> {
return a * b;
};
MathOperation division = (a, b) -> a / b;
interface MathOperation {
int operation(int a, int b);
}
The sample simply assigned lambda expression to MathOperation interface's variable but how ? It makes a implementation of method named operation which is in the interface and the point I was confused is assignment of that implementation to the variable of interface. I really wonder the idea based on this approach. Thank you in advance to all.