? RTTI how to break the limit -? Reflection

If you do not know the exact type of an object, RTTI can tell you, but there is a limit: the type must be known at compile time, in order to use RTTI recognize it, that is, at compile time, the compiler must know all through RTTI to the handling.

This limitation can break through? Yes, it is a breakthrough reflection.

Class class libraries together with the concept of reflection java.lang.reflect were support, the library comprises a Field, Method and Constructor class (each class implements the interface Member). These types of objects are created at run time by the JVM, to represent the members of the class corresponding to the unknown. So you can use the Constructor to create a new object, reading get () / set () method and modify the fields associated with Field objects, methods and associated Method object using invoke () method call. In addition, can also call getFields (), getMethods () and getConstructors () like a very convenient method returns an array of objects to fields, methods and constructors. Thus, class information anonymous objects can be completely settled at run time, but at compile time does not need to know anything.

Guess you like

Origin blog.51cto.com/14512197/2446569