- Reflecting the main target
- Class
- Constructor
- Field
- Method
- API-Class
- Gets the Class object
Object.getClass()
className.class
Class.forName()
Class.getComponentType()
Element to obtain an array of objects of type
- Obtain Class information
getDeclaredClasses()
Returns the class defined in a public, private, protected internal classes and interfaces. But does not include inherited inner classes and interfacesgetClasses()
Back to the public's internal classes and interfaces defined in the class, as well as from the parent class, inherited parent interface to the internal classes and interfacesgetClassLoader()
Returns the class loader to load such
getConstructors()
Returns public constructorsgetDeclaredConstructors()
Back to all constructorsgetFields()
Get all public member variablesgetDeclaredFields()
Get all member variables
getDeclaredMethods()
All public access to such methods, including inheritancegetDeclaredMethods()
Defined in this class get in all the methods (public, private), but does not include inherited methods
- Produced objects
newInstance()
Use only no-argument constructor
- Gets the Class object
- API-Field
- Information acquisition member variable classes (including instance variables and class variables)
- Get the variable name
field.getName()
- Gets variable type
field.getType()
- Gets a variable parameter type for generics
field.getGenericType()
- Make Variable modifiers
field.getModifiers()
have the meaningModifier类
- Get the class where the variable
field.getDeclaringClass()
- Get the variable name
- The value of the member variables to read and write
Read the member variable values
// public field.get(foo) // private field.setAccessible(true) field.get(foo)
Modify the value of member variables
field.set(foo, "123") // private field.setAccessible(true) field.set(foo, "123")
- Information acquisition member variable classes (including instance variables and class variables)
- API-Method
- Method for obtaining information
method.getName()
- ...
- Reflection method call
method.invoke()
- Method for obtaining information
- API-Constructor
newInstance()
Generating an object, you can use parameterized constructor
java reflection API
Guess you like
Origin www.cnblogs.com/bosslv/p/11364780.html
Recommended
Ranking