A detailed description of how class objects are obtained through class in Java

Source: Internet
Author: User

Way 1: Through the GetObject () method of the object class

 person p = new   person (); Class c  = P.getclass (); 

Mode 2: Gets a byte-code file object from the class name. Class (Any data type has a class static property that looks simpler than the first).

 Class c2 = Person. Class ; 

Mode 3: Pass a method in class (Forname a class literal to a static method in a class class)

 Class C3 = Class.forName ("person"); 

note : The difference between the third and the first two

The first two types of

You must specify the person type.

The

is followed by a string that specifies this type. This . I don't need to know the class name. I only provide strings, which can be loaded according to the configuration file

 

Reference: https://www.jb51.net/article/122246.htm

 

A way to get a class object in Java using the class class

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.