This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enum class - equals() and hashCode() ?" Watch "Enum class - equals() and hashCode() ?" New topic
Author

Enum class - equals() and hashCode() ?

kri shan
Ranch Hand

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

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

Joined: Oct 27, 2005
Posts: 20128
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enum class - equals() and hashCode() ?
 
It's not a secret anymore!