Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

When is enum type applicable?

Thread view: 
- - 24 Jul 2005 05:14 GMT
If enum type cannot be subclassed, using MouseWheelEvent and MouseEvent
as an example where the former is the latter's subclass, how can the
constants be made into enum type?

Static constants from MouseEvent:

static int MOUSE_CLICKED

static int MOUSE_DRAGGED

// etc
// ...

Static constants from MouseWheelEvent:

static int WHEEL_BLOCK_SCROLL

static int WHEEL_UNIT_SCROLL

or is enum type not applicable in this matter? if so, when is enum
applicable?
Chris Smith - 24 Jul 2005 05:24 GMT
> If enum type cannot be subclassed, using MouseWheelEvent and MouseEvent
> as an example where the former is the latter's subclass, how can the
> constants be made into enum type?

...

> or is enum type not applicable in this matter? if so, when is enum
> applicable?

Enumerations are definitely not applicable in that case.  There are
several reasons for enums, but the one Java chose to focus on is type
safety; an enum guarantees that the variable will not have any value
except those listed.  The ability to subclass and add more possible
values would violate that guarantee, because those values would need to
be assignment-compatible with the supertype.

Where are enums applicable?  Anywhere you have a set of possible values
that you DO want to enforce strictly.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Roedy Green - 24 Jul 2005 10:14 GMT
>If enum type cannot be subclassed, using MouseWheelEvent and MouseEvent
>as an example where the former is the latter's subclass, how can the
>constants be made into enum type?

Each enum constant can be its own inner anonymous class with its own
methods and member variables.

Just write something like this

enum {  RED( a, b, c ) { void m( x ) { ...} },

m is a method of inner class RED which is also an enum constant.
a, b, c are parms to its constructor.

Signature

Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.