Where is ".class" declared in java?
I just noticed that I can create any class (say MyClass) and do
Class a = MyClass.class
MyClass only extends from the Object class, but I checked the documentation for the Object class but couldn't find a field named " class
". Where does this field come from?
+3
DesirePRG
source
to share
1 answer
It is called a "class literal" and is formally defined in this section of the Java language specification:
A class literal is an expression consisting of the name of a class, interface, array, or primitive type or void pseudorange, followed by a '.' and a token
class
.
This expression, the keyword class
does not represent a member of the type.
+5
manouti
source
to share