What is a “runtime class” in Java?

I try to understand object The function of the getClass () method

Documentation means that it "returns the runtime class of the object" This explanation did not help me understand the term

Someone briefly described what the "runtime class" is and what the role of getClass () is?

Solution

It only needs to be understood as "an object with all metadata of object type" In this object, you can find the methods, fields, type hierarchies, etc. declared in the class

You can emphasize "runtime" because the class definition may change over time, or the object may be declared as a supertype when it is actually an instance of a subtype of the declared subtype When a class is loaded, it is the information loaded in the instance, which will be returned by the getClass () method

In short, when your code runs, the VM will be with you The "source" form typed in the java file defines your class in different ways Of course, after compilation, this information will be loaded, and all metadata (as described above) will constitute what they call "runtime classes" It's just a strange way to say "an object that contains all the metadata about the class loaded when the program runs."

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
分享
二维码
< <上一篇
下一篇>>