Streams – Fundamentals
In Chapter 14, we learned about lambda expressions. Lambda expressions enable us to write more concise code. Be aware, however, that the compiler is, in the background, inserting the code we omit. For that to work, the compiler must have no decisions to make. This is where “functional interfaces” come into play. A functional interface is an interface with just one abstract
method; this is known as the “functional method.” Lambda expressions can only be used with functional interfaces.
We saw that if a local variable is used in a lambda expression, that variable must be final
or “effectively final.” This keeps both views (method and lambda) of the variable’s value in sync. In other words, both the method and the lambda have the same value for the variable at all times.
We also examined the more popular functional interfaces in the API, namely, Predicate
, BiPredicate
, Supplier
, Consumer
, BiConsumer
,...