JDK-8196589 : add compiler support for local-variable syntax for lambda parameters
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2018-02-01
  • Updated: 2018-02-22
  • Resolved: 2018-02-22
Related Reports
CSR :  
Relates :  
Description
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](http://openjdk.java.net/jeps/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.


Comments
After the explanation of the issues with the initial patch, moving to re-approve the CSR.
22-02-2018

The compilation error that happened with the previous version of the patch doesn't invalidate, the minimal risk assumption for the JEP. An existing heuristic in the parser was "massaged" to yield very specific error messages for the new feature but in that effort we broke an existing code path that was being used by previously existing lambdas with nothing to do with the new feature. We changed that approach and let the existing heuristics untouched and we are now analyzing the lambda parameters after this heuristic has been applied. This should minimize, modulo bugs, any possible interaction with previously existing / acceptable lambdas
22-02-2018

Given the compilation error which happened after this change was pushed, the implementation has a higher than "minimal" compatibility impact. I'm pending the request until a full compatibility assessment can be done.
21-02-2018

Moving to Approved.
16-02-2018