It's just not the same thing. String
is a class of type string, and String.member
is one of its member variables, String.method()
would be one of its methods.
String.class
is an object of type Class
that defines String
. It seems a lot more intuitive that you need to specify .class
to indicate that you're trying to refer to an object of type Class
.
Not to mention that it's easier to parse this kind of construct, and potentially prevents bugs where you're accidentally returning a Class
object when you didn't mean to.
This is even more relevant when you're looking at inner classes, like OuterClass.InnerClass.class
.
To work with Matt's example: How would you work on the class object without having to create a temporary variable first? Assuming your class Foo
has a static method called getClasses
, how would you differentiate between Foo.getClasses
and Foo.class.getClasses
?