java reflection API

  1. Reflecting the main target
    1. Class
    2. Constructor
    3. Field
    4. Method
  2. API-Class
    1. Gets the Class object
      1. Object.getClass()
      2. className.class
      3. Class.forName()
      4. Class.getComponentType() Element to obtain an array of objects of type
    2. Obtain Class information
      1. getDeclaredClasses()Returns the class defined in a public, private, protected internal classes and interfaces. But does not include inherited inner classes and interfaces
      2. getClasses() 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 interfaces
      3. getClassLoader() Returns the class loader to load such
      4. getConstructors() Returns public constructors
      5. getDeclaredConstructors() Back to all constructors
      6. getFields() Get all public member variables
      7. getDeclaredFields() Get all member variables
      8. getDeclaredMethods() All public access to such methods, including inheritance
      9. getDeclaredMethods() Defined in this class get in all the methods (public, private), but does not include inherited methods
    3. Produced objects
      1. newInstance() Use only no-argument constructor
  3. API-Field
    1. Information acquisition member variable classes (including instance variables and class variables)
      1. Get the variable name field.getName()
      2. Gets variable type field.getType()
      3. Gets a variable parameter type for generics field.getGenericType()
      4. Make Variable modifiers field.getModifiers()have the meaningModifier类
      5. Get the class where the variable field.getDeclaringClass()
    2. The value of the member variables to read and write
      1. Read the member variable values

        // public 
        field.get(foo)
        // private
        field.setAccessible(true)
        field.get(foo)
      2. Modify the value of member variables

        field.set(foo, "123")
        // private
        field.setAccessible(true)
        field.set(foo, "123")
  4. API-Method
    1. Method for obtaining information
      1. method.getName()
      2. ...
    2. Reflection method call
      1. method.invoke()
  5. API-Constructor
    1. newInstance() Generating an object, you can use parameterized constructor

Guess you like

Origin www.cnblogs.com/bosslv/p/11364780.html