Summary
Two changes proposed:
The current specification for Pattern Matching in
instanceof
allows declaration annotations on the pattern variables, butjavac
does not currently support them.The specification for Pattern Matching in
instanceof
has been recently updated to allow thefinal
modifier (with the usual meaning and grammar) on pattern variables;javac
needs to be updated to accept them as well.
Problem
Two issues:
javac
does 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) {} } }
javac
does not support a recent change to the specification to allow thefinal
modifier 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
-