Summary
Based on experiences with the several rounds of preview of record patterns, we propose a reduction in the feature. We also propose to make the feature final and permanent.
Problem
We've identified that the record patterns in enhanced for loops, introduced in the previous round of preview, may need a significant redesign, to better align with other features under consideration. The rest of the record patterns feature is, however, well vetted. We therefore propose to drop the record patterns in enhanced for loops sub-feature, and finalize the record patterns feature without this sub-feature.
The rules for exhaustiveness of switch statements and expressions in presence of record patterns were found to not be sufficient. A new set of rules for exhaustiveness is being proposed as a solution to this problem.
Solution
The record patterns in enhanced for loops sub-feature will be dropped from:
- the specification
- the javac implementation
- the Trees API. The relevant
EnhancedForLoopTree.getVariableOrRecordPattern
,EnhancedForLoopTree.getDeclarationKind
andInstanceOfTree.getTestKind
methods andEnhancedForLoopTree.DeclarationKind
andInstanceOfTree.TestKind
enums are marked as preview API, and therefore can be removed.
The exhaustivity rules for switches in presence of record patterns will be enhanced. Please see CSR JDK-8304394 for more details.
The rest of the record patterns feature will be made final and permanent.
Specification
The specification draft is available for convenience here and is attached as" 20230509 Pattern Matching for switch and Record Patterns.pdf". Please note that, for technical reasons, the specification draft also includes changes for JEP-441 (https://openjdk.org/jeps/441), which are reviewed under CSR JDK-8304394.
The specdiff of API changes is available here and is attached as specdiff.00.zip. Please note that, for technical reasons, the specdiff also includes changes for JEP-441 (https://openjdk.org/jeps/441), which are reviewed under CSR JDK-8304394.
The feature will be made final and permanent.
- csr of
-
JDK-8300545 Compiler Implementation for Record Patterns
- Resolved
- relates to
-
JDK-8284529 Compiler implementation for Record Patterns
- Closed
-
JDK-8294944 Compiler implementation for Record Patterns (Second Preview)
- Closed