Fix Version/s: 16
Compatibility Risk Description:Two reflective preview methods in BindingPatternTree have been removed and replaced with a new method. As a preview API, the users of the API were warned, and should be prepared to update their code.
Interface Kind:Java API, Language construct
The Java language feature "pattern matching for
instanceof", currently a second round of preview in JDK 15, is to be made final and permanent in JDK 16. Several, small adjustments to the feature are proposed.
The proposed Java language feature "pattern matching for
instanceof" has been through two rounds of preview, which has resulted in some feedback. Adjustments based on the feedback should be made to the feature, and it should be made final and permanent.
The following changes have been made to the design of the feature and are taken from the JEP (394):
Lift the restriction that pattern variables are implicitly final, to reduce asymmetries between local variables and pattern variables.
Make it a compile-time error for a pattern
instanceofexpression to compare an expression of type
Sagainst a pattern of type
Sis a subtype of
instanceofexpression will always succeed and is then pointless. The opposite case, where a pattern match will always fail, is already a compile-time error.)
The following changes address implementation improvements:
The Trees API has been modified so that
VariableTreethat declares the actual binding variable. This is to improve consistency of the API.
The feature is made non-preview, including removing preview warnings from modelling APIs.
The draft specification is attached and is also available for convenience here. The specification draft enumerates the more significant changes in the introduction, which can be summarized as follows:
- To support non-final binding variables: changes primarily to sections 4.11 and 4.12.3, and also a slight change to the grammar for type test patterns in section 220.127.116.11.
- To ensure the compile-time error for expression type being a subtype of the pattern type: changes to section 15.20.2
- Some refactoring of the description of the semantics of pattern instanceof: changes to sections 15.20.2 and 14.30.3
The specdiff of the API adjustment is attached and is also available for convenience here: http://cr.openjdk.java.net/~jlahoda/8250625/specdiff.01/overview-summary.html.