Class Object Test

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.