I have come across code in the form:
MyClass.class.getName();
Is .class a property?
Is it applicable to ALL classes? (is it inherited from Object class?)
What type of object is returned by .class ?
What other functions like getName() does the .class have?
I realize that this is a very basic question, but I wasn’t able to locate comprehensive information in the Javadocs, and it would be really helpful if some practical application of .class could be given.
Thanks in advance.
MyClass.classis a literal value of typeClass(the same way as"..."is a literal value of typeString).It’s available for all classes and interfaces, and also for primitive types (
int.class).Since
Classis generic, type ofMyClass.classisClass<MyClass>, so that you can do this:Methods of
Classcan be found in its javadoc.