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

前端 未结 5 1496
一整个雨季
一整个雨季 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 05:02

    It is precisely because the Java designers could not think of any conceivable use case for overriding Enum.equals(Object) that that method is declared as final - so that such overriding would be impossible.

提交回复
热议问题