This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 1372
Whether enum classes need object's equals() and hashCode() ?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38075
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: 19656

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
It is sorta covered in the JavaRanch Style Guide.
subject: Enum class - equals() and hashCode() ?
Similar Threads
what is hashcode and equals contract?
HashSet ordering
map method containsKey
Cannot understand enum class syntax
On Sets