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


Win a copy of Java 8 in Action this week in the Java 8 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: 1368
Whether enum classes need object's equals() and hashCode() ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
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: 19557
    
  16

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() ?
 
Similar Threads
Cannot understand enum class syntax
map method containsKey
what is hashcode and equals contract?
On Sets
HashSet ordering