why java Object class has two methods hashcode() and equals()? One of them looks redundant and its percolated to the bottom most derived class?
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.
Why do you think one is redundant? They say different things:
hashCodeis “give me some way of efficiently seeing whether two objects are likely to be equal”equalsis “check whether this object is genuinely equal to another”You definitely need both – although I don’t believe they should really be in Object in the first place.
You absolutely need hash codes in order to perform efficient lookups with hash tables – and you absolutely need further equality checks because hashes will collide (there are far more possible strings than hash codes, for example).