jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Enumns - Pros/Cons? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enumns - Pros/Cons?" Watch "Enumns - Pros/Cons?" New topic

Enumns - Pros/Cons?

Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi everybody,

I wondered if somebody could explin the benefits/purpose of using Enums?
I've also heard you need to be careful with them also..?

Any thoughts would greatly be appreciated.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Read this article
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Hi Nigel,
I checked the article which you have provided but unable to understand what exactly is the int enum pattern?

In prior releases, the standard way to represent an enumerated type was the int Enum pattern:
// int Enum Pattern - has severe problems!
public static final int SEASON_WINTER = 0;
public static final int SEASON_SPRING = 1;
public static final int SEASON_SUMMER = 2;
public static final int SEASON_FALL = 3;

Thanks in advance


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Vladimir Nesov

Joined: Jun 18, 2006
Posts: 20
It means that standard way of implementing enums was as you quoted, that is using integer constants.
Note that typesafe enum pattern was still not significantly more difficult, and enum keyword is just some syntactic sugar upon such pattern.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
It also provides for some rather interesting and powerful functionality to have a full firstclass type as an enumeration rather than a primitive.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Enums are a great way to implement simple Strategy classes with a fixed set of implementations.

The only drawback of enums is that they can't inherit from other classes (because they already implicitely inherit from the enum base class)..

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link: http://aspose.com/file-tools
subject: Enumns - Pros/Cons?
It's not a secret anymore!