Why equals and hashCode were defined in Object?

前端 未结 10 1243
天命终不由人
天命终不由人 2020-12-06 05:50

What\'s the reasoning behind decision to include these methods in the java.lang.Object? Equality and hashing doesn\'t make sense for many classes.

It would be more l

10条回答
  •  不知归路
    2020-12-06 05:59

    Originally, in Java, there were no generics. This was worked around by allowing any Object to be a member of any collection, and thus any Object needed hashCode and equals. By now it's too entrenched to change.

提交回复
热议问题