Overriding equals() & hashCode() in sub classes … considering super fields

前端 未结 10 1260
一个人的身影
一个人的身影 2020-12-07 13:19

Is there a specific rule on how Overriding equals() & hashCode() in sub classes considering super fields ?? k

10条回答
  •  温柔的废话
    2020-12-07 13:50

    Regarding the accepted @CPerkins answer, I don't think the given equals() code will work reliably, due to the likelihood that the super.equals() method will also check for class equality. A subclass & superclass will not have equal classes.

提交回复
热议问题