What does .class mean after a class name

前端 未结 3 1328
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-25 12:03

What does .class mean in, for example, MyClass.class? I understand that when you put the name of a class and the point it is used to access its sta

3条回答
  •  一向
    一向 (楼主)
    2020-12-25 12:49

    SomeClass.class gets the Class type which you can use for programming using the reflection API.

    You can get the same type if you have an instance of the class using instance.getClass().

    You can check out the documentation here. For example, you can:

    • get the names of fields and methods, annotations, etc.
    • invoke methods, get constructor to create new instances of the class
    • get the name of the class, the superclass, package, etc

提交回复
热议问题