Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > When is enum type applicable?

Reply
Thread Tools

When is enum type applicable?

 
 
-
Guest
Posts: n/a
 
      07-24-2005
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?
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-24-2005
- <(E-Mail Removed)> wrote:
> 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.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-24-2005
On Sun, 24 Jul 2005 12:14:46 +0800, - <(E-Mail Removed)> wrote or
quoted :

>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.


--
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/...s_rumsfeld.htm

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: an enum question - how to convert enum type to a string? Roedy Green Java 0 02-27-2010 04:52 AM
Re: an enum question - how to convert enum type to a string? Wojtek Java 1 02-27-2010 03:44 AM
Re: an enum question - how to convert enum type to a string? Lew Java 0 02-27-2010 03:40 AM
Re: an enum question - how to convert enum type to a string? Eric Sosman Java 3 02-26-2010 03:36 PM
enum within an enum - Java 6 06-13-2005 12:51 AM



Advertisments