Tag: ADC size reflection for memory pre. Class generic Generation
A. Class understanding
/ * * Class is the source of reflection * Create a class, compile (Javac.exe), generate the corresponding. class file, and then use Java.exe to load (completed by the JVM's ClassLoader) this. class file. * When this. class file is loaded into memory, it is a runtime class that is stored in the cache. * then this runtime class is itself an instance of class. * 1. Each runtime class is loaded only once; * 2. Once you have an instance of class, you can do the following: * 1> Create objects of the corresponding runtime class * 2> Gets the complete structure of the corresponding run class (properties, methods, constructors, inner classes, parent classes, packages, exceptions, annotations 、... * 3> calls the corresponding runtime class for the specified structure (properties, methods, constructors) * 4> Reflection application: Dynamic Agent */
A method of acquiring a class object
1) obtained by class's Static property class
Class clazz = Person.class;
2) obtained by the GetClass method of the runtime class
person person = new person (); Class clazz = Person.getclass ();
3) obtained by the static method of class
String className = "Hello." Person ";//The fully qualified name of the run-time class, class Clazz = Class.forName (className);
4) obtained through the class loader (learn)
String className = "Hello." Person ";//The fully qualified name of the class ClassLoader ClassLoader = This.getclass (). getClassLoader (); Class clazz = Classloader.loadclass (className);
Second, create an instance object of the corresponding run-time class through the class object
Class Clazz = person.class;//does not use generics, default is the class object of object type person person = (person) clazz.newinstance (); A strong turn is required, and the method defaults to calling the run-time class's parameterless construction method, so the class must have no parameter construction method, the permission is large enough class<person> clazz1 = person.class;// A generic is used that specifies the class object of the person type person Person1 = clazz1.newinstance ();//does not require a strong turn
Java Reflection feature One