aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enumns - Pros/Cons?" Watch "Enumns - Pros/Cons?" New topic
Author

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

Naseem


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

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.


42
Ilja Preuss
author
Sheriff

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?
 
Similar Threads
sick of work
what is urs
newbie question: How to rate replies ?
Clarify my doubt in listeners
Pune Product based companies