When overriding equals in Java, why does it not work to use a parameter other than Object?

后端 未结 7 1939
攒了一身酷
攒了一身酷 2020-12-03 18:13

I ran into an interesting behavior recently. It seems that if I override .equals() to take a parameter other than Object, it doesn\'t get called. Can anyone explain to me

7条回答
  •  长情又很酷
    2020-12-03 18:20

    equals(Object) is overriding a super method; you can not override a super method without using the exact same signature (Well, there are some exceptions like covariant returntypes and exception).

提交回复
热议问题