Java Reflection mechanism

Source: Internet
Author: User

Summarize the relevant knowledge points of the Java reflection mechanism,

I. What is reflection

The Java reflection mechanism is in the running state, for any class can know its properties and methods, for any object can call its properties and methods, this dynamic access to information or the function of dynamic Call object method is called Java Reflection mechanism;

Two. Three ways to get class

 1  Public classFanshe {2     //three ways to get a class object 3      Public Static voidMain (string[] args) {//product is the base class of its own definition, placed in the Fanshe package 4Product p =NewProduct ();5         //1. Through the GetClass () of the object; 6Class C1 =P.getclass ();7System. out. println (C1.getname ());8         //2. Static class properties by data type 9Class C2 = Product.class;TenSystem. out. println (c1==C2); One         //3. Static Methods A         Try { -Class C3 = Class.forName ("Fanshe. Product");//string full path contains package name -System. out. println (c3==C2); the}Catch(ClassNotFoundException e) { -             //TODO auto-generated Catch block -e.printstacktrace (); -         } +     } -}

Java Reflection mechanism

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.