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.
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.
The record patterns in enhanced for loops sub-feature will be dropped from:
- the specification
- the javac implementation
- the Trees API. The relevant
InstanceOfTree.TestKindenums 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.
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.