JDK-8315851 : Compiler Implementation for Unnamed Variables & Patterns
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 22
  • Submitted: 2023-09-07
  • Updated: 2023-11-30
  • Resolved: 2023-10-20
Related Reports
CSR :  
Relates :  
Relates :  
Description
Summary
-------

[JEP 443](https://bugs.openjdk.org/browse/JDK-8294349) previewed the Java
language with unnamed variables, which can be initialized but not used, and
unnamed patterns, which match a record component without stating the component's
name or type. Both are denoted by an underscore character, `_`. We propose to
make this feature final and permanent.

Problem
-------

Since no changes were requested we propose to make the feature final and
permanent. 

Solution
--------

No essential implementation changes are proposed apart from removing the
`--enable-preview` protection and making the Tree API for underscore
(`AnyPatternTree`) permanent. The removal of the `@PreviewFeature` will be the
only part of the API changes.

The `javax.lang.model` will be also finalized accordingly. The previous changeset was tracked in a separate 
[CSR: 8307577: Implementation for javax.lang.model for unnamed variables (Preview)](https://bugs.openjdk.org/browse/JDK-8307577).

Specification
-------------

The specification draft was reviewed under 
[CSR JDK-8304246](https://bugs.openjdk.org/browse/JDK-8304246). 
There are no new updates to the specification.

The previously proposed API enhancements are not enhanced or altered. 
The preliminary specdiff will be attached as 8315851.specdiff.zip.

The changes to the specification and API are a subject of change until the CSR
is finalized.



Comments
Re-affirming Approval of the CSR with the corrected specification update; thanks.
30-11-2023

The JEP describes (already from the preview) the form of lambda formal parameters with an underscore in place of an identifier, e.g., `_ -> "NODATA"`. While the JEP and the compiler are in agreement, the JLS was missing an adjustment needed in the grammar. JLS updated with the missing *15.27.1 Lambda Parameters* section that defines the relevant form.
30-11-2023

Moving to Approved.
20-10-2023

Moving to Provisional, not Approved. [~abimpoudis], please file a separate bug to track the updates to javax.lang.model and com.sun.source. That helps track the changes for the JSR 269 maintenance review.
27-09-2023