Reflection is to get all the information of a class, including both methods and properties.
1. The method of acquisition includes obtaining the name of the method, the return type of the method, the access modifier of the method, and the execution of this method through reflection.
2. Get the property including the name of the property, type, access modifier, and the value of this property.
All of these gains have the appropriate API to provide operations.
The code is as follows:
Package poi;
Import Java.lang.reflect.Constructor;
Import Java.lang.reflect.Field;
Import Java.lang.reflect.Method;
Import Java.lang.reflect.Modifier;
Import org.apache.poi.xwpf.usermodel.XWPFSettings; public class Reflectmain {public static void main (string[] arg) throws SecurityException, Nosuchfieldexception, Illegala Rgumentexception, Illegalaccessexception, classnotfoundexception, instantiationexception{XWPFSettings ct = new
Xwpfsettings ();
Class C = Ct.getclass ();
System.out.println ("---------------------the member variable-----------------------of the specified class");
System.out.println ("Number of member variables for reflected class");
System.out.println (C.getdeclaredfields (). length);
For (Field Fil:c.getdeclaredfields ()) {System.out.print (Fil.gettype () + "");
System.out.println (Fil.getname ());
} System.out.println ("Method of constructing------------------------class-----------------------"); For (constructor constructor:c.getdeclaredconstructors ()) {System.out.print (modifier.tostring (
Constructor.getmodifiers ()) + ""); System.out.println(Constructor.getname ());
} System.out.println ("--------------------------member Method--------------------------");
For (Method Method:c.getdeclaredmethods ()) {System.out.print (modifier.tostring (Method.getmodifiers ()) + "");
System.out.print (Method.getreturntype () + "");
System.out.println (Method.getname ());
} System.out.println ("Modifiers------------------------for---------------------------class");
int mod = C.getmodifiers ();
String modifier = modifier.tostring (mod);
System.out.println ("modifier =" + modifier);
System.out.println ("------------------------the fully qualified name--------------------of the specified class");
System.out.println (C.getname ());
System.out.println ("------------------------the parent class qualified name--------------------" of the specified class);
System.out.println (C.getsuperclass (). GetName ()); }
}
The above is a description of how the Java reflection to get a class of all the content, I hope that the future study of everyone to help, but also hope to work with you to learn and progress.