Why Java does not allow overriding equals(Object) in an Enum?

前端 未结 5 1492
一整个雨季
一整个雨季 2020-12-03 04:18

I\'ve noticed that the following snippet...

@Override
public boolean equals(Object otherObject) {
    ...
}

...is not allowed for an Enum,

5条回答
  •  再見小時候
    2020-12-03 04:53

    There is already provides a strong intuitive notion of what it means for instances (values) of an enum to be equal. Allowing the overloading the equals method would lead to that notion being violated, leading to unexpected behavior, bugs and so on.

提交回复
热议问题