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.)
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.)
- duplicates
-
JDK-4117369 javac refuses to compile InterfaceName.class, but fastjavac works
-
- Closed
-
-
JDK-4093023 Class Literals: interfaceI{Class c=I.class;}, causes errors and should not
-
- Closed
-