Summary
JEP 323: Allow var
to be used when declaring the formal parameters of implicitly typed lambda expressions
Problem
The syntax of a formal parameter declaration in an implicitly typed lambda expression is not aligned with the syntax of a local variable declaration. See JEP 323 for more discussion.
Solution
The parser will allow the formal parameters of an implicitly typed lambda expression to be denoted with var
. A var
applied to a formal parameter of an implicitly typed lambda expression will be ignored and the inferred type will be exactly the same as not using var
at all. Like the distinction between implicit and explicit lambdas itself, using this syntax is all-or-nothing; either all parameters must be declared with var, or none.
Specification
Proposed changes to the Java Language Specification are attached.
- csr of
-
JDK-8194892 (Original) Add compiler support for local-variable syntax for lambda parameters
- Resolved
- relates to
-
JDK-8193259 JEP 323: Local-Variable Syntax for Lambda Parameters
- Closed