GeekInterview.com
Series: Subject: Topic:
Question: 46 of 573

Should i override Equals and hasCode methods while implementing Comparable interface??

somewhere I read we should override equals() and hasCode() methods while implementing Comparable interface... I could not understand why should i do so... Kindly help.. thx in advance.
Asked by: singh.virendra18 | Member Since Apr-2011 | Asked on: Apr 4th, 2011

View all questions by singh.virendra18

Showing Answers 1 - 1 of 1 Answers

Equals () : It must define an equality relation.In addition it must be consistent(if the objects are not modified , then it must keep returning the same value)

HashCode() : It must also be consistent(if the objects is not modified in terms of equals(), it must keep returning the same value
If you override one, you should override the other

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.