Creating a Multiline Lambda Expression

 
FileWriterEAM.use(​"eam2.txt"​, writerEAM -> {
 
writerEAM.writeStuff(​"how"​);
 
writerEAM.writeStuff(​"sweet"​);
 
});

We should keep the lambda expressions short, but it’s easy to sneak in a few lines of code. We have to pay penance by using curly braces {}, and the return keyword is required if the lambda expression is expected to return a value.

Get Functional Programming in Java 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.