Why equals and hashCode were defined in Object?

前端 未结 10 1192
天命终不由人
天命终不由人 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

    Any object, regardless of its type, can sensibly answer whether it's equivalent to any other object, even if the other object's type is one it's never heard of. If it's never heard of the other object's type, that fact alone is sufficient for it to report that it isn't equivalent to the latter object.

提交回复
热议问题