Java type information

Thinking in Java 4th chapter 14 type information

Run time type identification enables you to find and use type information when the program is running.

14.1 why RTTI is needed

The three classes of circle, square and triangle inherit from the abstract class shape. There is an array of lists, which stores the objects of circle and triangle. When you take out an object, you only know that it is a shape class, but you don't know its specific type. Using RTTI, you can query the specific type of the object pointed to by a space reference.

14.2 class objects

Java uses the class object to execute its RTTI, which contains class related information. Each class has a class object, which is stored in a class with the same name Class file. In order to generate objects of this class, the JVM running this program will use a subsystem called "class loader".

All classes are dynamically loaded into the JVM when they are first used. The class is loaded when the program creates the first reference to a static member of the class. Therefore, the Java program is not fully loaded before it starts running. Its parts are loaded when necessary.

The class loader first checks that the class object of this class has been loaded. If it has not been loaded, the default class loader will find it according to the class name Class file. Once the class object of a class is loaded into memory, it is used to create all objects of the class.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>