What is a “runtime class” in Java?

后端 未结 4 1180
故里飘歌
故里飘歌 2021-01-12 11:51

I try to understand what the Object.getClass() method does.

The documentation says that it \"returns the runtime class of an object.\" That explanation

4条回答
  •  执念已碎
    2021-01-12 12:53

    Every class you write has a lot of metadata. That metadata consists of the class name, its fields, its methods, its base classes, the interfaces it implements, and so on.

    Sometimes you may need to access that metadata from your code at runtime.

    In order to do so, you can take any object and call its getClass() method. You will receive a Class object that will contain the above metadata.

提交回复
热议问题