Reflex is that it can get all the information of a class, which mainly includes two parts: method and attributes.
1. The method of obtaining the method includes the name of the method, the return type of the method, the method of access to the method, and this method through reflection.
2. Get the attribute includes the name, type, access to modifier, and the value of this attribute.
These gains have the corresponding API to provide operations.
The code is as follows:
package poi; Import Java.lang.reflect.ConStructor; Import Java.lang.reflect.field.field; Import Java.lang.reflect.method; Import Java.lang.reflect.modifier ; Import org.apache.poi.xwpf.usermodel. XWPFSETITINGS; Public Class ReflectMain {Public Static Void Main (String [] Arg) Throws SecurityException, NoSuchFieldException, Illegalargumenterxcexce PTION, IlLegalaccessexception, ClassNotFoundexception, InstantiaTexception {xwpfsettings CT = New XWPFSettings (); Class C = CT.GetClass () ; System.out. Println ("--------------------------------------------------------------------------------------------------------------------------------------------------------------- -"); System.out.println (" Number of members variables obtained by reflexes "); System.out.println (c.getDeclaredfields (). LENGTH); for (Field Fil: C.GetDeCladfields ()) {System.out.print (fil.gettype ()+""); System.out.println (fil.getName ());} System.out.println ("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------ Construction method of class ----------------------------------------------------------------------------------------------------------- "); ()) {System.out.print (modifier.tostring (constructor.getmodifiers ())+""); System.out.println (constructor.getName ());} System.out.println ("-" --- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------— "); for (Method MetHod: C.GetDeclaredMethods ()) {System.out.print (modifier.tostring (method.getmodifier ())); getReturnype ()+"" "" );; Method.getName ());} System.out.println ("--------------------------------------------------------------------------------------------------------------------------------- Class modifiers --------------------------------------------------------------------------------------------------------------------------------------------- "); int Mod = c.Getmodifiers (); String modifier = modifier.tostring (MOD); System.out.println("modifier = " + modifier); System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Name -------------------------"); System.out.println(c.getName()); System.out.println("------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- out.println (c.getsuperclass (). getname ());}}The above is the introduction of how to reflect in Java to get all the contents of a class. I hope it will be helpful to everyone's future learning. At the same time, I hope to learn and improve with the heroes.