| Author |
is it necessary to provide hashCode with equals
|
Ram Para
Ranch Hand
Joined: Jul 09, 2008
Posts: 48
|
|
|
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: 19216
|
|
|
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
How To Ask Questions How To Answer Questions
|
 |
Lucas Alberione
Greenhorn
Joined: Aug 15, 2009
Posts: 8
|
|
|
See this post
|
Lucas
|
 |
 |
|
|
subject: is it necessary to provide hashCode with equals
|
|
|