aspose file tools*
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
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: 1382
Whether enum classes need object's equals() and hashCode() ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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: 19785
    
  20

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
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() ?