#What is reflection in java?
Java reflection means that in the running state, for any class, we can know what methods and attributes this class has. For any object, we can call its methods and properties. We call this function of dynamically obtaining object information and calling object methods a reflection mechanism.
Java reflection method
I need to tell you here that the so-called reflection is actually to obtain the bytecode file of the class, that is, the .class file. Then we can obtain it through the Class object.
Method 1:
This method is actually a method of Object. Class inherits Object, so we can use it directly.
Method 2:
Method 3:
It should be noted here that through the entire class Obtaining the Class object by path name will throw an exception. If the class cannot be found based on the class path, this exception will be thrown.
Recommended tutorial:java tutorial
The above is the detailed content of what is reflection in java. For more information, please follow other related articles on the PHP Chinese website!