Dropping Parentheses for a Single-Parameter Inferred Type

 
friends.forEach(name -> ​System​.out.println(name));

The parentheses () around the parameter are optional if the lambda expression takes only one parameter and its type is inferred. We could write name -> ... or (name) -> ...; lean toward the first since it’s less noisy.

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.