|
关于第29题:
Equals & Hash Code relationship - The last note from the API documentation is very important, it states the relationship requirement between these two methods. It simply means that if two objects are equal, then they must have the same hash code, however the opposite is NOT true. This is discussed in details later in this article.
注意,这里只是API文档。所以,在Sun提供的Java API中,29的答案是对。但是,对于用户自己创建的类,我觉得由于Java Language Specification中没有定义这两者之间的关系,所以用户完全可以创建一个equals()成立而hashCode()不相等的类。等我有更多时间的时候试验一下。 |
|