Where is ObjectClass.class variable defined/initialized?
Consider sample code below
public class Test {
public static void main(String args[]) {
Test t = new Test();
Class c2 = Test.class;
System.out.println(c2);
}
}
Test.class statically evaluates and returns compile time Class object.
Looking at the Test.class syntax it looks like the variable class is of
type java.lang.Class and is static and public. My question is where is
this variable defined? It is not present in Test class (because I don't
declare it) neither it is in the java.lang.Object class.
I saw an analogous method public final native Class<?> getClass();. This
is present in java.lang.Object and is a native java method. This method
returns the runtime Class of an object.
So my question is where is this public & static class variable
defined?(Please correct me if I have mistaken) Is it again some native
implementation? This is set at compile time and being static needs no
class instance to be created. So if even this is some native
implementation is it initialized by registerNatives() method in
java.lang.Object?
No comments:
Post a Comment