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

9.7.4: Fix illegal examples of "admissible" type annotations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 15
    • 14
    • specification

      JLS14 9.7.4 gives the following example:

      -----
      @Target(ElementType.TYPE_USE)
      @interface Foo {}

      class Test {
        class A {
          static class B {}
        }

        @Foo A.B x; // Illegal
      }
      -----

      However, it is a compile-time error for class B to be declared static in the first place, per 8.5.1: "The static keyword may modify the declaration of a member type C within the body of a non-inner class or interface T." (A is an inner class above.)

      The example can easily be fixed by making A into a top level class. Then, it is non-inner, so class B can be declared static.

      The final example in 9.7.4, involving classes Test, E, F, and G, is too complicated and should be removed. (It involves a hypothetical whereby an illegal nest of classes is assumed to be legal for the purpose of noting a technicality in the definition of "admissible". This adds confusion faster than it adds clarity.)

            abuckley Alex Buckley
            gbierman Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: