JavaWhat is reflection?
Official definition: The JAVA reflection mechanism is in the running state , for any class, can know all the properties and methods of the class ; Any one of its methods and properties can be called for any object ; This dynamic acquisition of information about a class and the ability to dynamically invoke the object's methods are known as the reflection mechanism of the Java language.
Understanding: Gets A feature of a running Java object.
JavaWhat is the reflection function?
1. Determine the class to which any object belongs at run time;
2. Constructs an object of any class at run time;
3. Determine the member variables and methods of any class at run time;
4. Method of invoking any object at run time;
5. Generate the dynamic agent.
Implementing JavaWhat are the reflected classes?
1.Class: It represents classes and interfaces in a running Java application
2.Field: Provides information about the properties of a class or interface, as well as the dynamic access rights to it
3.Constructor: Provides information about a single construction method of a class and access to it
4.Method: Provides information about a method in a class or interface
Note: The class class is the most important feature class in Java reflection, and all information that gets the object (including: Method/attribute/constructor/access) needs it to implement
How to do JavaReflective programming?
1. First get the class object
There are three ways to accomplish this:
Class C1 = Test.class;
Class C2 = class.forname ("Test");
Class C3 = New Test (). GetClass ();
2. Then call the methods in the class object to get information about the properties, methods, and construction methods in a class.
Java Reflection Mechanism Learning