Dear all,

Currently enums do not have a well-defined hashCode() implementation so
they defer to Object.hashCode() which just uses an internal mechanism
to determine the hashcode, likely based on the object's place in the
heap.

This may confuse a lot of developers as other classes such as String do
have a well-defined hashcode which is consistent across multiple JVM's.

Could it be a good idea to make enums' hashCode() method more reliably
and predictable? For instance by using the hashcode of the name of its
value?

For example:

class MyEnum { A, B }
-> A.hashCode() == A.name().hashCode()

Kind regards,

Dave Franken

Reply via email to