To get the class object, we use MyClass.class. It seems that the "class" is a static member of "MyClass",

To get the class object, we use MyClass.class. It seems that the "class" is a static member of "MyClass"

  • Is the "class" a static member of "MyClass"?

  • If so, when is it added and who is adding this field?

+4
source share
1 answer

Despite the similar syntax, class not a static member of each class. The C.class expression is called a class literal and is a special syntax that the compiler understands.

It is defined in the specification :

A class literal is an expression consisting of the name of a class, interface, array, or primitive type or pseudo-type void followed by '.' and class token.

+8
source

All Articles