Reflective essays

Exit: Soul frame design
    frame: the frame may be performed on the basis of software development, a simplified encoded
    reflection: the respective portions of wrapper classes for other objects

advantages:
    1. These objects can operate the program is running
    2 can be decoupled, improved scalability program

acquiring class object
    1.Class.forname ( "full class name"): the bytecode file loaded into memory, the object return class
    2. class name .class: acquiring attribute class by class name
    3. Object .getclass (): getclass () method is defined in the object class
    Conclusion: the same bytecode files (* .class) during a program run, it is loaded only once, regardless of the target acquisition class by way of which are is the same




Class object functions:
    1. obtain function:
        Gets the member variables are
        Field [] getFields () Gets all public member variables modified
        field getField (String name) Gets the name of the modified public member variables
        Field [] getDeclareFields () get all member variables
        field getDeclareField (String name)
        Gets constructor who
        constructor <?> getConstructors ()
        Constructor <T> getConstructor (Class <?> ... parameterTypes)
        Constructor <?> GetDeclareConstructors ()
        Constructor <T> getDeclareConstructor (Class <?> ... parameterTypes)
        acquisition method are members of
        Method, [] getMethods ()
        Method, [] (<?> String name, class ... parameterTypes) getMethod
        Method, [] getDeclareMethods ()
        Method, [] getDeclareMethod (<?> String name, class ... parameterTypes)    
        Gets the class name
        String getName ()


    Field,: member variables
    1. set the value of
    the sET (Object obj, Object value)
    2. Gets the value
    get (Object obj)


    ignores access modifiers security checks
    d.setAccessible (true) // violence reflected

    constructor: constructor
    create objects
    newInstance ()
    when the object is created with an empty argument constructor, the operation can be simplified: newInstance Class object

    Method: Method Object
    execution method:
        Object Invoke (Object obj ..... args)
    method for obtaining name:
    String getName

Guess you like

Origin www.cnblogs.com/ashin1997/p/11355174.html