最重要的有三条:(用英文写是因为它们给我印象太深了)HashCode() is explicitly used in methods where hash functions are used, like hashTable() etc.One should always override hashCode() when overriding equals(). Unexpected behaviour will occur if you don't do so.HashCode() should have the same value whenever equals() returns true.
用hashcode来比较比用equals好
String的HashCode()是在String被用作Key时(插入HashTable)产生Hash code,在String的equal()中也用到了HashCode()。这两者的作用是不一样的,只是在String的实现中恰好可以用来比较。(这也说明Java的String.HashCode()写得好,可以产生独一无二的Hash code!)
一句话:在比较object时使用equal()
在需要object作为key(使用HashTable)时使用Hashcode()
以上是我的理解,如果有什么不对的地方,请大家指导我
谢谢