开发者社区 问答 正文

equals()和hashCode()方法被隐式调用时的约定

网上看到那么一个问题,百度了一下没有找到合适的答案.

展开
收起
蛮大人123 2016-02-25 10:56:29 2463 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    JDK源码的注释说明的很清楚,如果重写了equal方法,也应该重写hashCode方法。看看源码注释吧,是非常好的文档资料呢。
    *Note that it is generally necessary to override the hashCode

    • method whenever this method is overridden, so as to maintain the
    • general contract for the hashCode method, which states
    • that equal objects must have equal hash codes.
    2019-07-17 18:47:17
    赞同 展开评论
问答地址: