In my new job we often use “.class” approach to get the name of some class. In the beginning I thought that “.class” is a some public field of class Object which every Java class extends from Object but it was wrong.
The “.class” syntax is part of Java Reflections. Here is the explanation of “.class” from Java Online Tutorial:
If the type is available but there is no instance then it is possible to obtain a
Class by appending
".class" to the name of the type. This is also the easiest way to obtain the
Class for a primitive type.
It is a great fun to say on the primitive type int “int.class”, isn’t it? :) It works and returns “int” as text result to my surprise.
Here is the link for the .class syntax in the Official Java Online Tutorial.