When learning the reflection mechanism, summarize how to get the class object:
The first way: to get objects by the class itself
class<?> classname = This.getclass (); or This.class.
The second way: Get the parent class object through an instance of the child class
ClassName cn = new ClassName ();
UserClass = Cn.getclass ();
class<?> Subuserclass = Userclass.getsuperclass ();
Third Way: Get objects by class name Plus. class
Class<?> Forclass = **.**. Classname.class; (class in Package path Plus. Class)
Fourth way: Get an object from a string of class name
class<?> forname = Class.forName ("**.**. ClassName ");
This approach is commonly used in JDBC.
Class<?> and Class differences:
In the class<?>? is a wildcard, in fact, is to represent any class that conforms to the conditions of the generic class definition, and the direct use of the class effect is basically consistent, but this is more canonical, in some types of conversion can avoid unnecessary unchecked errors.
The role of the class object: You can view the class
Class Loader Object
Reflection: Get object construction methods, properties, methods and annotations, note that the annotations here are the annotations of the class itself, rather than the annotations of the internal properties or methods, to get the corresponding method through the annotations, you can traverse the method and then judge the time to include the annotation, and the property and method object itself is the annotation property.
You can create an instance: Class.newinstance ()
Java class objects use