Understanding lambda expressions
Lambda expressions save on keystrokes and therefore make your code more concise and hence, more readable and maintainable. For this to work, the compiler has to be able to generate the code that you no longer type in. This brings us to our first topic: functional interfaces. To understand lambdas, we must first understand functional interfaces.
Functional Interfaces
Recall that an interface has default
, static
, private
, and abstract
methods. A concrete (non-abstract) class that implements an interface must provide code for all of the abstract
methods. A functional interface is an interface with just one abstract method – default
, static
, and private
methods do not count. Neither do any methods inherited from Object
. This one abstract
method is known as the functional method.
Lambda expressions
A lambda expression is an instance of a class that implements a functional interface. The lambda is boiled down to its bare essentials. Lambdas...