Not really sure if there is a specified "contract" on what a hashcode method must do (other than return an int). The only thing to keep in mind is the following:
1. If two objects point to the same reference (i.e. a == b), then the hashcode for a and b MUST return the same value.
2. If the hashcode for a and b are equal, the objects MAY point to the same reference, but not necessarily.
If you are going to write your own custom hashcode method, make sure the above two items still hold true. Normally, the equals method is overriden if the hashcode method is, but not always (it depends on the implementation).
Basically, if two objects are "equal" as defined by the equals method, then they must return the same hashCode. If they are not equal as defined by the equals method, then they are not required to return the same hashCode. Note that "equality" is defined here by the equals method, and not a simple reference comparison (==). [ February 09, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
A wop bop a lu bop a womp bam boom! Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss