Hi Atul,
Lambda expressions and method references are similar to Scala's anonymous functions in the sense that they let you pass a piece of code around in a concise way.
Java *had* to provide a similar feature so it doesn't stay behind compared to other programming languages. Lambda expressions are great for Java because:
- they encourage a
pattern called "behaviour parameterisation" which enables more flexible APIs
- they are very concise compared to alternative way of doing the same thing (i.e. using anonymous classes)
Note that in Scala's, functions are in general richer (we detail this in chapter 12 of our book):
- Scala provides function types, a syntactic sugar to represent the idea of function descriptors
- Scala provides anonymous functions that do not have the write restrictions on non-local variables that lambda expressions have (i.e anonymous functions capture variables and not values as with lambdas).
- Scala provides support for currying: breaking down a function that takes multiple arguments into a series of functions that take part of the arguments.