I have read quite a considerable stuff about lambda. But their are subtle doubts:
Q1. Definition of lambda expressions.
- I didnt find clear definition on oracle page.
- This link says "A Java lambda expression is thus a function which can be created without belonging to any class."
- This link says "Lambda Expression is a concise representation of an anonymous function that can be passed around."
- This link says "Lambda expressions basically express instances of functional interfaces "
2nd and 3rd link does no say anything about functional interfaces. Fourth link sounds somewhat good, but misses to state "anonymous" aspect of lambda expressions. Can we define them more perfectly like this:
Lambda expressions are "syntactically concise expressions to define anonymous implementations of functional interfaces".
I believe specifying word "functional interface" in definition, should be enough to state that we implement its only method and it behaves like function, instead of class, even though are anonymous classes.
Q2. Do we differentiate between lambda and lambda expressions?
I feel there is a difference, because lambda expressions are can be used to define both lambda which are stateless and closures which are stateful (i.e. access variables in outer lexical scope). Seems that, thats why oracle link does not use word "lambda" without "expression". However that is not the case with other links.
Q3. This link says, with lambda expressions, "We don’t need to write a lot of boilerplate like we do for anonymous classes." Now this sounds like "Lambda expressions are like anonymous classes, its just that", "we don’t need to write a lot of boilerplate like we do for anonymous classes." I feel we cannot straight compare lambda expressions with anonymous classes, for major difference is concept anonymous class has no connection with functional interfaces, while lambda expressions are strictly dealing with functional interfaces. So anonymous classes can have any number of methods, but lambda expressions can only define single method. Am right with this?