Home > Java > javaTutorial > What is the principle of java reflection

What is the principle of java reflection

silencement
Release: 2019-05-30 17:20:00
Original
4181 people have browsed it

What is the principle of java reflection

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 c = Class.forName ("Full path of the 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template