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

Class literals don't work in interfaces

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.1.3, 1.1.4, 1.1.5, 1.2.0
    • tools
    • None
    • 1.2beta4
    • generic, x86
    • solaris_2.5.1, windows_nt
    • Not verified

      the 1.1 inner classes spec defines the following addition to the java
      language:
       
              PrimaryNoNewArray:
                       ...
                       Type . class
                       void . class
       
      it further states: "For reference types, a class literal is equivalent
      to a call to Class.forName with the appropriate string, except that it
      does not raise any checked exceptions."
       
      i am assuming that this specification is correct. the jdk1.1.1 compiler
      compiles expressions of the form Type.class where Type is not a
      primitive to "$class( Type )" where $class is a static method generated
      by the compiler in the class or interface in which the expression
      occurs.
       
      the problem is that interfaces can't define static methods, so the
      jdk1.1.1 javac cannot compile the following:
       
        public interface I {
          Class c = I.class;
        }
       
      i would think that defining $class() in every class that contains a
      Type.class expression is a waste of space anyways. why didn't javasoft
      just put a single copy of the method in Class? the efficiency is the
      same, isn't it?
       
      interestingly, the microsoft sdk2.0 jvc will compile the code above
      (using the same $class() construct as javac) without error and generate
      an illegal class file. however, the jdk1.1.1 vm does not detect the
      error (due to bugs i've posted about previously). in fact, i don't know
      what the vm actually does when it hits the invocation of the illegal
      method I.$class(), but a reference to I.c evaluates at runtime to null.
      (the microsoft vm, on the other hand, will not load the invalid
      interface.)

            wmaddoxsunw William Maddox (Inactive)
            dstoutamsunw David Stoutamire (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: