I want to create a hashmap of classes like (Object.class). I am wondering whether
Object.class is considered equal to another Object.class?
Can there be another instance of Object.class which leads it to have different hashcode?
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.
The literal
Object.classwill always return the same reference within the same classloader.From section 15.8.2 of the JLS:
Note the definite article (“the”) in the quote above – there’s only one
Classobject for any particular class, within the same class loader.So yes, you’ll get the same hashcode – because you’ll have two references to the same object.