Private Static void test for the same Class Object (){
Class <Class Object test> A = Class Object test. Class;
Class <Class Object test> B = Class Object test. Class;
System. Out. println (A = B); // true;
Class <Class Object test> C = NULL;
Try {
C = (class <Class Object test>) class. forname ("com. Cai. Test. Class Object test ");
} Catch (classnotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
System. Out. println (A = C); // true;
Class Object test instance = New Class Object test ();
Class <? Extends Class Object test> d = instance. getclass ();
System. Out. println (A = D); // true;
}
True is printed in all three cases, which at least indicates that the class object generated in the above case is the same.
Baidu. The process of generating class objects is actually like this:
When we compile a new Java class, JVM will compile it into a class object and store it in the same name. Class file. During runtime, when an object of this class needs to be generated, JVM will check whether the class has been loaded into memory. If it is not loaded, load it. The class file is loaded into the memory. If it is loaded, the instance object is generated based on the class file.