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.

Questions by singh.virendra18

Showing Answers 1 - 6 of 6 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

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions