It's not a secret anymore!*
The moose likes Java in General and the fly likes Use of Enums over Interface constants ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Use of Enums over Interface constants ?" Watch "Use of Enums over Interface constants ?" New topic
Author

Use of Enums over Interface constants ?

Ramesh Kumar
Ranch Hand

Joined: Oct 29, 2008
Posts: 42
HI
i need a clear idea about , why we go for Enum constants instead of interface constants .
what is the main difference ??
please post your comments on it .

Thank you
Rameshkumar


SCJP,OCA
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Advantage of using enum:

1) can you in the switch case
2) can use the properties of an Enum class like using constructor etc
3) no need to implement the enum. can be used as an other class imported.

Prefer Enum only when all the constants belong to same category,. like No of days, Currencies etc.


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Ramesh Kumar
Ranch Hand

Joined: Oct 29, 2008
Posts: 42
thank you .im clear now
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Constant Interface Anti-pattern
 
wood burning stoves
 
subject: Use of Enums over Interface constants ?