I am attempting to do the equivalent of
if ( object1.class == object2.class )
{
//do something
}
which of course doesn’t work, what method am I overlooking?
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.
If they’re from the exact same class:
Now if they are compatible classes (if one is of a descendent class to the other):
As LinkedHashMap is a subclass of HashMap this result variable will be true, so this might probably be better for you as it’s going to find exact and subclass matches.
Also, you should avoid using “.class” on variables, as it might not give you the correct result, example:
When you’re using “.class” you’re acessing the variable static property and not the class of the object itself.