When you create your own key object for use in a Hashtable
, you must override the
Object.equals()
and
Object.hashCode()
methods since Hashtable
uses a combination of the key's hashCode()
and equals()
methods to store and retrieve its entries quickly. It's also a general rule that when you override equals()
, you always override hashCode()
.
重写equals():
1.没有重写equals()意味着什么?
2. 设计equals()方法
3.equals()约定
重写hashCode():
1.理解散列码
2.设计hashCode()
3.hashCode()约定重写equals():