|
CSR :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
Summary
-------
Several minor bugs in the Java Language Specification for the "Pattern Matching for `instanceof`" feature have been identified, and fixed. The feature will remain a preview feature for JDK 15.
Problem
-------
As a feedback to the "Pattern Matching for `instanceof`" preview feature, there were two minor bugs identified:
1. The following code would not compile per the spec (as it contained no handling for parenthesized expressions):
if ((o instanceof String s)) {
System.err.println(s); //the binding variable does not propagate through the parenthesized expression per JLS
}
2. The following code would not compile per the spec (as it contained no handling for labeled statements):
LABELED: if (o instanceof String s) ; else throw new IllegalStateException();
System.err.println(s); //labeled statements didn't introduce any variables into the scope, even if the nested statement would.
Solution
--------
Sections 6.3.1.7 Parenthesized Expressions, and 6.3.2.7 Labeled Statements have been added to the specification to fix the above problems.
The feature "Pattern Matching for `instanceof`" will continue to be a preview feature in JDK 15.
Specification
-------------
The updated specification is updated as patterns-instanceof-jls-20200413.zip, with a simple diff against the previous specification attached as JDK-8242368-diff.zip. The specification is also available for convenience here: http://cr.openjdk.java.net/~gbierman/jep375/jep375-20200413/specs/patterns-instanceof-jls.html
The only non-editorial changes to the specification compared to the JDK 14 version of the specification is the addition of sections 6.3.1.7 and 6.3.2.7.
|