When is enum type applicable?

?

-

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?
 
C

Chris Smith

- said:
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
 
R

Roedy Green

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top