Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8257759

Binding variables don't correct support declaration annotations and the final modifier

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 16
    • tools
    • None
    • source
    • minimal
    • Language construct

      Summary

      Two changes proposed:

      1. The current specification for Pattern Matching in instanceof allows declaration annotations on the pattern variables, but javac does not currently support them.

      2. The specification for Pattern Matching in instanceof has been recently updated to allow the final modifier (with the usual meaning and grammar) on pattern variables; javac needs to be updated to accept them as well.

      Problem

      Two issues:

      1. 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) {}
         }
        } 
      2. javac does not support a recent change to the specification to allow the final 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.

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: