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?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
uu dd
  • 521
  • 4
  • 8

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
  • 291,719
  • 55
  • 540
  • 600