15

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 ...

Get Learn Java with Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.