Could anyone please explain what does SomeClassname.class return in JAVA ?? I cant understand what it does ..
Could anyone please explain what does SomeClassname.class return in JAVA ?? I cant understand
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It returns the same what Object.getClass() does for a given instance, but you can use it when you know statically what class you want (i.e. at compile time).
From the Javadoc:
In short, it gives you an object that represents the class of the (original) object. It’s used, amongst other things, by reflection when you want to programatically discover methods and fields in order to invoke/access them.
For example:
The Javadoc also refers you to the Java Language Specification – Class Literals (which might be a little heavy reading).