First, what is type information?
Simply understood, "type information" is a mechanism that is implemented in Java by discovering and using "class" information during program operation.
Java type information consists of two main components: Rtti and reflection.
Second, what is Rtti?
RTTI, the full name is run-time type information, the meaning of which is to recognize the type of an object at run time.
1.Class objects
In Java, a special object class is used to perform its rtti (this is an idea that uses a class to represent all types of objects, to distinguish which type is by the attributes in the specific class, and to use similar ideas in spring. All the beans in spring are represented by Beandefinition.
All classes are dynamically loaded into the JVM when they are first used, and the ClassLoader first checks to see if the class object is already loaded, and if it is not already loaded, the default ClassLoader will look for the. class file based on the class name; It is used to create all objects of this class.
Take a look at two examples to understand the process of downloading:
1 Public classClasstest {2 Static {3System. out. println ("classtest");4 }5 Public Static voidMain (String[]args) {6 7 }8 }9 Ten classCandy { One Static { ASystem. out. println ("Candy"); - } -}
The results are as follows:
In the Classtest class, when the main method is executed, the Classtest class is loaded automatically, and the class has static method block static, so the classtest is displayed;
In the Candy class, the candy class is not loaded because it has not been used for its elements.
Look again:
1 Public classClasstest {2 Public Static voidMain (String[]args) {3System. out. println (candy.i);4 }5 }6 7 classCandy {8 Public StaticFinalintI=1;//Define a constant9 Ten Static { OneSystem. out. println ("Candy"); A } -}
The results are as follows:
In this example, constants are determined during compilation, so calling Candy.i in the main function does not actually need to load the Classtest type information, so there is no execution of the statement in the static block.
2. The literal of the class
1 Public classClasstest {2 Public Static voidMain (String[]args) {3System. out. println (boolean.type);4System. out. println (Boolean.class);5System. out. println (Boolean.class);6 7 }8}
The results are as follows:
Ix. type information in Java