Mark Guo wrote:What's the difference between hashcode() and equals() methods?
Literally, what the others have said is absolutely right; and I'd also suggest that you look at the API docs for Object.
Logically, they should be as similar as possible, given any other constraints you might have, such as time. That is to say that equal hashcodes should
strongly indicate equal objects; however, a near-perfect
hashCode() method won't be much use if it takes 10 seconds to run.
In addition to the other suggestions,
Effective Java has a very good chapter on hashcodes in general, and the requirements of
equals() and
hashCode() as used together.
Winston