what must be hashcode of null objects in Java?

后端 未结 4 1407
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-19 23:14

According to a comment from this post, hascode of null objects can throw NPE or a value of zero. This is implementation speci

4条回答
  •  自闭症患者
    2021-02-19 23:49

    If you will search around, you'll notice that HashMap has a special handling for null keys. null values are fine as you don't compute hash code for them in a HashMap. This is the reason why null keys work fine in HashMap. As to why Objects.hashCode works fine, take a look at Rohit's answer.

提交回复
热议问题