Suppose x and y are of type MyEnum
, which is an enum.
What is the best way to test whether x and y refer to the same constant?
toString()
.equals(y.toString()
)) hashCode()
== y.hashCode()
) A.
It is not possible to have two instances of an enum that represent the same value.
So the == operator is reliable, and it's faster than any method call.