This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Enum class - equals() and hashCode() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enum class - equals() and hashCode() ?" Watch "Enum class - equals() and hashCode() ?" New topic

Enum class - equals() and hashCode() ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1368
Whether enum classes need object's equals() and hashCode() ?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36478
Start in the Java™ Language Specification. Remember enum members are singletons, so == is adequate as a test for equality.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19541

Besides, all enum classes implicitly extend java.lang.Enum which has final implementations of both. equals uses == and hashCode uses Object.hashCode. Try overriding them in any enum and you'll get a compiler error.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Enum class - equals() and hashCode() ?
Similar Threads
HashSet ordering
Cannot understand enum class syntax
On Sets
map method containsKey
what is hashcode and equals contract?