網(wǎng)管下載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需要知道,如果不對(duì)Object的hashCode對(duì)象復(fù)寫(xiě),則其它生成規(guī)則是根據(jù)內(nèi)部的指針地址來(lái)算出hashCode。(這一點(diǎn)大家得特別注意)
下面是eclipse生成代碼的一個(gè)示例:
它的問(wèn)題就是,result中調(diào)用了 *super.hashCode()。*這么一來(lái),同一個(gè)類被實(shí)例化多次后,雖然它們的名稱都相同
但生成的hashCode都不同,當(dāng)然在那些集合類中使用返回的也會(huì)有問(wèn)題了。