CSR :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Summary ------- 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. Problem ------- 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. Solution -------- 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 `instanceof` expression to compare an expression of type `S` against a pattern of type `T`, where `S` is a subtype of `T`. (This `instanceof` expression 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 `BindingPatternTree` contains a `VariableTree` that 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. Specification ------------- The draft specification is attached and is also available for convenience <a href="http://cr.openjdk.java.net/~jlahoda/8250625/jep394/jep394-20201026/specs/patterns-instanceof.html">here</a>. 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 14.30.1.1. * 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.
|