7.2.  Create and use lambda expressions with local-variable type inferred parameters

[Note]
  • [JEP_323] JEP 323: Local-Variable Syntax for Lambda Parameters

From Java 11 you can use the var reserved type name as lambda expression parameter type:

					
UnaryOperator<String> lc = (var s) -> s.toLowerCase();

					

The type of the parameter declared with the var above will be inferred to the type String, because the type declaration of the variable has its generic type set to UnaryOperator<String>, which means that the parameter type and return type of the UnaryOperator is String.

Legal lambda expression type inferrence usage

Illegal lambda expression type inferrence usage

Professional hosting         Exam 1Z0-817: Upgrade OCP Java 6, 7 & 8 to Java SE 11 Developer Quiz     Exam 1Z0-810: Upgrade to Java SE 8 Programmer Quiz