posted 13 years ago
In addition to this, always override hashCode() when you override equals() in your own classes. I will show you with a piece of code what happens when you don't. It will prevent your class from working correctly when you use a hash-based collection, such as a HashMap.
Here is the bad code:
And here is the better code: