Java record-89-java. lang. Class
As we all know, Java has an Object class, which is the root inheritance of all Java classes. It declares several methods that should be rewritten in all Java classes: hashCode (), equals (), clone (), toString (), getClass (), etc. GetClass () returns a Class object. The Class class is very special. It inherits from the Object like the general classes. In fact, it is used to express the classes and interfaces when Java is running. It is also used to express enum, array, primitive Java types (boolean, byte, char, short, int, long, float, double) and keyword void. When a class is loaded, or when the defineClass () of the loader (Class loader) is called by JVM, JVM automatically generates a Class object. In the Java JDK source code, we can see that the Constructor of the Class is private, and the comments are: Constructor, Only the Java Virtual Machine creates Class objects. Only the Java Virtual Machine can create Class objects. The Class contains many native methods, that is, local methods, which are implemented by C or C ++ instead of Java. Class is the origin of Reflection. For any Class you want to explore, you can only generate a Class object for it first. Then, the latter can evoke dozens of Reflection APIs. Java allows us to generate the corresponding class object for a Class in multiple ways: 1. use getClass (); (each class has this function) 2. use Class. getSuperclass (); 3. use static method Class. forName (); (most commonly used) 4. application. class syntax (Class str = String. class) 5. use the TYPE Syntax of primitive wrapper classes (Class c1 = Integer. TYPE)