Java reflex mechanism acquires the full structure of the runtime class

Field, Method, Constructor, Superclass, Interface, Annotation

? All interfaces implemented

? The parent class inherited

All constructor

All methods

Whole Field

Use reflection can be obtained:

1. All interfaces implemented

PUBLIC CLASS <?> GetInterfaces

Determine the interface or interface implemented by this object.

2. The parent class inherited

PUBLIC CLASS <? Super T> getsuperclass

Returns the Class of the parent class representing the entity (class, interface, basic type) represented by this Class.

3. All constructor

PUBLIC Constructor <T> getConstructors

Returns all public constructors of the classes represented by this Class object.

PUBLIC Constructor <T> getDeclaredConstructors

Returns all constructors of class declarations represented by this Class object.

CONSTRUCTOR class:

? Get the modifier: public int getModifiers;

? Method name: public string getname;

Get the type of parameters: public class <?> GetparameterTypes;

4. All methods

Public Method getDeclaredMethods

Returns all methods for classes or interfaces represented by this Class object

PUBLIC METHOD GETMETHODS

Returns the method of publication of the class or interface represented by this Class object

Method class:

PUBLIC CLASS <?> GetReturntype acquires all return values

PUBLIC CLASS <?> getParameterTypes acquires all of the parameters

Public Int getModifiers get modifies

PUBLIC CLASS <?> getExceptionTypes acquired exception information

5. All Field

Public Field getFields

? Returns the PUBLIC of the class or interface represented by this Class object.

Public Field getDeclaredfields

? Returns all Field of the classes or interfaces represented by this Class object.

? Field method:

Public IntModifiers Returns this Field modifier in an integer

PUBLIC CLASS <?> gettype gets the property type of the Field

PUBLIC STRING GETNAME Returns the name of the Field.

6. ANNOTATION related

? Get Annotation (Class <T> AnnotationClass)

? GetDeclaredannotations

7. Wild related

8. Category package package getpackage

Summary:

1. In the actual operation, the operation code of the information obtained is not often developed.

2. Be sure to be familiar with the role of java.lang.Reflect package, reflection mechanism.

3. How to get attributes, methods, names, modifiers, etc. of the constructor.