When should I define an hash code function for my types?
Posted
by devoured elysium
on Stack Overflow
See other posts from Stack Overflow
or by devoured elysium
Published on 2010-06-13T21:16:15Z
Indexed on
2010/06/13
21:22 UTC
Read the original article
Hit count: 125
Is there any other reason for implementing an hash code function for my types other than allowing for good use of hash tables?
Let's say I am designing some types that I intend to use internally. I know that types are "internal" to the system, and I also know I will never use those types in hash tables. In spite of this, I decide I will have to redefine the equals() method.
Theory says I should also redefine the hash code method, but I can't see any reason why, in this case, I should do it.
Can anyone point me out any other reason?
This question can be rephrased to : in which situations should we implement a hash code method in our types.
PS : I am not asking how to implement one. I am asking when.
© Stack Overflow or respective owner