Reflection Class usage, reflection class

Source: Internet
Author: User

Reflection Class usage, reflection class
Any Class is an instance object of the Class. This instance object has three representation methods.

  • The first representation (any class has an implicit static member variable class ):

1 Class c1 = Foo. class;

  • The second representation (this class object is known through the getClass method ):
1 Foo foo1 = new Foo (); 2 Class c2 = foo1.getClass ();
※C1 and c2 indicate the class type of the Foo class)
  • Third Representation
1 Class c3 = null; 2 try {3 c3 = Class. forName ("com. format. test. foo "); 4} catch (ClassNotFoundException e) {5 e. printStackTrace (); 6}
※Create an object instance of this class through the class type
1 try {2 Foo foo2 = (Foo) c1.newInstance (); // requires parameter construction 3} catch (InstantiationException e) {4 e. printStackTrace (); 5} catch (IllegalAccessException e) {6 e. printStackTrace (); 7}

 

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.