看板
[ java ]
討論串關於HashSet 加入重覆物件卻成功加入的問題
共 9 篇文章
內容預覽:
tkcn , good guess!!! thank you for your response. after tracing JDK(1.4.2) HashSet I have some answer here.. First of all, Inside HashSet there is a H
(還有1327個字)
內容預覽:
HashSet 可以放同一個物件兩次嗎? :P. 我沒有去看 HashSet 的 source code. 但是我猜想流程大概是以下這個樣子. 1. 呼叫傳入物件的 hashcode(),計算出物件存放的位址. 2a. 如果該位址尚未存放其他物件,則將傳入的物件存入。接著結束這個 method。.
(還有145個字)
內容預覽:
Sorry to type in English.. It seems to be different from your result. My testing result shows only following output without the equals function. Anyon
(還有1599個字)
內容預覽:
之後每次插入element時. hashcode() 跟equals(Object)都會 call到. equals回傳true 且hashcode()傳出相同整數時候. HashSet才會視作相同物件. 謝謝各位. --. ※ 發信站: 批踢踢實業坊(ptt.cc). ◆ From: 140.11
(還有6個字)