• Framework: semi-finished software, which can be developed on the basis of the framework and simplify the code

  • Reflection: Encapsulates parts of a class into other objects

    • Advantages:
      1. These objects are manipulated during the execution of the program.
      2. Can be decoupled, improve the scalability of the program.
  • There are three ways to get a Class object:

    1. Class. ForName (” full name “); (Mostly used in configuration files, the class name can be defined in the configuration file, read the file load class)

      Load the bytecode file into memory

    2. Class :(mostly used for passing parameters)

      By an attribute of the class name

    3. Object.getclass () (mostly used to get bytecode for objects)

      Through the Object method, which is defined in Object

    • Conclusion:

      The same bytecode file (.class) is loaded only once during a run,

      The Class is the same no matter how you get it, right

  • The Class object does the following:

    • Access function:

      1. Get member variable s:

        Filed[] getFiles() : Obtain all public member variables

        Field getFiled(String Name) : Obtains a public member variable with a specified name

        Filed[] getDeclaredFiles() : Obtain all member variables

        Field getFiled(String Name) : Gets the member variable whose name is set

      2. Get constructor s:

        Constructor[] getConstructors()

        Constructor getContructor(class<? >… parmeterTypes)

        Constructor[] getConstructors()

        Constructor getContructor(class<? >… parmeterTypes)

      3. Get the member method s:

        Method[] getMethods() : Gets all member methods

        Method getMethod(String name, Class ParmeterTypes) : Gets a single member Method

        Method[] getDeclaredMethods() : Gets all member methods

        Method getDeclaredMethod(String name, class ParmeterTypes) : Gets a single member Method

      4. Get the class name:

        String getName() : Gets the class name

  • Field: member variable

    • 1. Set value: void set(Object obj, Object value) 2. 3. Ignore security checks for access modifiers (violent reflection) : setAccessible(true)
  • (4) Constructor

    • Operation:

      1. Creating an Object: T newInstance(Object… , initargs)

      2. Create an empty parameter T newInstance() == class.newinstance

  • Method: indicates the member Method

    • Operation:
      1. Object invoke(Object obj, Object… args)

      2. Obtain method name: String getName