A DESCRIPTION OF THE REQUEST :
I discovered, that java.lang.Enum.hashCode() returns default hashCode value.
It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.
JUSTIFICATION :
It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Enum.hashCode() should return Enum.ordinal() value
ACTUAL -
Enum.hashCode() returns default Object.hashCode() value
I discovered, that java.lang.Enum.hashCode() returns default hashCode value.
It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.
JUSTIFICATION :
It does not contradict with JLS, but it would be more consistent to return Enum.ordinal() as hashCode() value which is unique, by it's definition.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Enum.hashCode() should return Enum.ordinal() value
ACTUAL -
Enum.hashCode() returns default Object.hashCode() value
- relates to
-
JDK-7190798 java enum hashcode not stable among JDK 7
- Closed
-
JDK-8306075 Micro-optimize Enum.hashCode
- Resolved
-
JDK-8252556 deepHashCode may be improved to generate consistent hash code
- Closed