In mathematics and computing generally, a lambda expression is a function: for some or all combinations of input values it specifies an output value. Lambda expressions in Java introduce the idea of functions into the language. In conventional Java terms lambdas can be understood as a kind of method with a more compact syntax that allows declarations to omit modifiers, the method identifier, the return type, and in some cases the parameter types.
I'm someone who does not get 'all excited' over object orientation. It's not that I have anything against it, I just don't have a lot for it. I would classify it in the same category as scrum or agile, more sizzle than steak. Could the same thing be said for lambda expressions, or am I missing something?
int SortCompare(int x, int y) {
return Math.signum(x-y);
}
void AnyFunc() {
Collection<int> collectionInput;
// .. fill the collection with some random unsorted numbers
Collection<int> collectionResult;
collectionResult = collectionInput.Sort(SortCompare);
}
void AnyFunc() {
Collection<int> collectionInput;
// .. fill the collection with some random unsorted numbers
Collection<int> collectionResult;
collectionResult = collectionInput.Sort((x, y) => Math.signum(x-y));
}
Lambda expressions are especially useful for short function definitions or "callbacks",
like DD showed. It's mostly syntactic sugar, but it is useful as you can access variables
of the outlining functions. I use those expressions quite often.