It allows var to be used when declaring the formal parameters of implicitly typed lambda expressions.
In Java 10, Local Variable Type Inference was introduced.
var str = "Java 10"; // infers Stringvar list = new ArrayList<String>(); // infers ArrayList<String>var stream = list.stream(); // infers Stream<String>svar bos = new ByteArrayOutputStream();
Java 11, allows var to be used to declare the formal parameters of an implicitly typed lambda expression.
(var a, var b) -> a + b
The examples below are illegal:
// Not allowed to mix 'var' and 'no var' in implicitly typed lambda expression(var a, b) -> a+b// Not allowed to mix 'var' and manifest types in explicitly typed lambda expression(var a, int b) -> a+b
Enregistrer pour revision