Did you ever think about how
Surprisingly or not it’s
1 2 3
it returns the
hashCode which is an internal address of the object to a certain extend. From the first glance it totally makes sense since
Enum values are singletons.
Now imagine you are building distributed system. Distributed systems use
- determine which worker in a cluster should handle part of a huge job
- determine which node in a cluster should store given item of dataset (e.g. in distributed cache)
Enum instance would give you a different
hashCode value in different JVMs/hosts, screwing up your Hadoop job or put/lookup in distributed storage. Just something I faced recently.