This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes is it necessary to provide hashCode with equals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is it necessary to provide hashCode with equals" Watch "is it necessary to provide hashCode with equals" New topic
Author

is it necessary to provide hashCode with equals

Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
Is it necessary to provide hashCode method when I am overriding equals method although I am not going to use the object with any Map implementation.


Ram Parashar
http://doinfinite.com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

Yes it is; that's how the contracts of both equals and hashCode work. When you override one, you must make sure the contract is not violated. You may not run into problems now, but in the future perhaps. And then it is so much harder to find out why errors occur.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Lucas Alberione
Greenhorn

Joined: Aug 15, 2009
Posts: 8
See this post


Lucas
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: is it necessary to provide hashCode with equals
 
It's not a secret anymore!