Summary
Two changes proposed:
- The current specification for Pattern Matching in - instanceofallows declaration annotations on the pattern variables, but- javacdoes not currently support them.
- The specification for Pattern Matching in - instanceofhas been recently updated to allow the- finalmodifier (with the usual meaning and grammar) on pattern variables;- javacneeds to be updated to accept them as well.
Problem
Two issues:
- javacdoes not handle declaration annotations properly on pattern variables. E.g. the following fails to compile:- public class A { public void test(Object o) { if (o instanceof @Deprecated String s) {} } }
- javacdoes not support a recent change to the specification to allow the- finalmodifier on pattern variables E.g. the following does not compile:- public class B { public void test(Object o) { if (o instanceof final String s) {} } }
Solution
The JLS will be updated to allow the final modifier on pattern variables.
javac will be updated to allow both the final modifier and declaration
annotations on pattern variables.
Specification
The full draft specification will be attached. The only non-editorial
change compared to state described in JDK-8254235 is that the final modifier
is allowed on the pattern variables, with the same grammar and semantics as for
local variables.
- csr of
- 
                    JDK-8256266 Binding variables don't correctly support declaration annotations and the final modifier -           
- Closed
 
-         
