0

Every Java class X can get its class name from X.class.

When I check it in the JDK documents, there isn't a member named class in Object.

Where does the class member come from?

uu dd
  • 521
  • 4
  • 9

1 Answers1

0

Foo.class is not a member of Foo, even though the syntax looks like it.

Foo.class is actually a Class Literal expression.

That means that it's just a special syntax in the language that's used to refer to the class of a given type.

If you used reflection to inspect Foo you wouldn't see a static field class.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614