Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get a Class object we use MyClass.class-It seems “class” is a static member of “MyClass”

Tags:

java

class

To get a Class object we use MyClass.class-It seems “class” is a static member of “MyClass”

  • Is “class” is static member of “MyClass” ?

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

like image 928
GBX Avatar asked Feb 18 '23 02:02

GBX


1 Answers

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

It's defined in the specification:

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

like image 74
Mark Byers Avatar answered May 15 '23 18:05

Mark Byers