1. What is JAVA reflection
1. In the running state, for any class, you can know the attributes of this class and methods.
2. For any object, you can call any of its methods and properties.
This function of dynamically obtaining information and dynamically calling object methods is called JAVA reflection.
2. The role of reflection
In JAVA, only given the name of a class, you can obtain all the information of the class through the reflection mechanism, and you can create it dynamically Objects and compilation.
3. The principle of reflection
After JAVA language is compiled, a .class file will be generated. Reflection is to find a certain class and methods in the class through the bytecode file. and attributes, etc.
The implementation of reflection mainly relies on the following four classes:
Class: object of the class
Constructor: constructor method of the class
Field: in the class Attribute object
Method: Method object in the class
Get the class object:
Get the Class object through the class name, Class
Get the specific class object through the Class object: Object o = (Object) c.newInstance();
The above is the detailed content of What is the principle of java reflection. For more information, please follow other related articles on the PHP Chinese website!