好的只是知识,如果hashmap
hashset
方法始终返回object's
,它会对hashcode
,0
等集合实现类有何意义在demoClass
中。我知道它与hashmap的putForNullKey
或其他类的Collection实现有关,但是不太了解细节。我知道对于null对象,hascode是0
所以它有0个哈希码的specfic方法。
@Override
public int hashCode() {
return 0;
}
答案 0 :(得分:2)
它会使HashMap
,HashSet
和其他依赖hashCode
的集合效率非常低,因为所有元素/条目都会添加到同一个bin中。
get()
,containsKey()
和contains()
等方法将O(n)
代替O(1)
。
hashCode
。任何常量hashCode
的行为都完全相同。