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

Type annotations on class literals are accepted by compiler when used with primitive types

XMLWordPrintable

    • b34

      According to the spec, type annotations on class literals are prohibited (http://baloo.ru.oracle.com/jenkins/job/jck8a-lang/lastSuccessfulBuild/artifact/build/out/htmlout/jls-15.html#jls-15.8.2-110)

      The following code, however, is accepted by the compiler:

      class Test {
         

          public static void test() {
              Class c = int @Simple [] .class; //compiles
          }

      }
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) @interface Simple {}


      The same code is not compiled if we use Integer instead of int:
      class Test {
         

          public static void test() {
              Class c = int @Simple [] .class; // javac error here
          }

      }
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) @interface Simple {}

      The situation is similar for other primitive types.

      Seems like a regression, because in b27 both cases were rejected by the compiler, and in b34 the situation is as described.


            jfranck Joel Borggrén-Franck (Inactive)
            enekipel Ella Nekipelova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: