網管下載dl.bitscn.com
ArrayList源代碼:
HashMap源代碼:
However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
但是每位PG需要知道,如果不對Object的hashCode對象復寫,則其它生成規則是根據內部的指針地址來算出hashCode。(這一點大家得特別注意)
下面是eclipse生成代碼的一個示例:
它的問題就是,result中調用了 *super.hashCode()。*這么一來,同一個類被實例化多次后,雖然它們的名稱都相同
但生成的hashCode都不同,當然在那些集合類中使用返回的也會有問題了。