比方說,我有一個CategoryKey
類:如何在Java中擴展HashSet?
public class CategoryKey {
public int layer;
public int parent;
public int child;
}
我試圖把它的許多情況下,Set
之內,但我們知道HashSet
不適合存儲自定義類的實例。那麼如何擴展java類HashSet
以滿足我的要求?或者我如何創建一個實現接口Set
的新類來解決同樣的問題?
「HashSet不適合存儲定製類的實例」爲什麼不呢? – EJP 2012-03-26 11:58:52
你是什麼意思「我們知道」? 'HashSet'非常適合存儲具有'.hashCode()'和'.equals()'的任何對象的實例。 – 2012-03-26 12:01:00
請涵蓋我的[HashSet的內部生活]教程(http://volodial.blogspot.com/2013/07/internal-life-of-hashset-in-java.html) – 2013-07-27 08:49:42