Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Is it possible to create Enum types at Runtime? What are the implications?

Reply
Thread Tools

Is it possible to create Enum types at Runtime? What are the implications?

 
 
Sideswipe
Guest
Posts: n/a
 
      08-03-2007
So, I want the nicities of an enum, but I would like to extend the
enum list at runtime. is such a thing possible?

Example:

public enum Day {
MONDAY("Sucks");
private String comment;
Day(String comment) {this.comment = comment;}

}

// create a new Day enum Day.TUESDAY
// then

switch(day) {
case TUESDAY:
....
}

I am nearly certain it isn't possible, but I thought I would ask
anyways.

Christian Bongiorno
http://christian.bongiorno.org

 
Reply With Quote
 
 
 
 
Piotr Kobzda
Guest
Posts: n/a
 
      08-03-2007
Sideswipe wrote:
> So, I want the nicities of an enum, but I would like to extend the
> enum list at runtime. is such a thing possible?
>
> Example:
>
> public enum Day {
> MONDAY("Sucks");
> private String comment;
> Day(String comment) {this.comment = comment;}
>
> }
>
> // create a new Day enum Day.TUESDAY
> // then
>
> switch(day) {
> case TUESDAY:
> ....
> }
>
> I am nearly certain it isn't possible, but I thought I would ask
> anyways.


Assuming that's possible, how would you compile the above without a
TUESDAY present at compile time?


piotr
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      08-03-2007
On Aug 3, 3:02 pm, Sideswipe <(E-Mail Removed)> wrote:
> So, I want the nicities of an enum, but I would like to extend the
> enum list at runtime. is such a thing possible?
>
> Example:
>
> public enum Day {
> MONDAY("Sucks");
> private String comment;
> Day(String comment) {this.comment = comment;}
>
> }
>
> // create a new Day enum Day.TUESDAY
> // then
>
> switch(day) {
> case TUESDAY:
> ....
>
> }
>
> I am nearly certain it isn't possible, but I thought I would ask
> anyways.
>
> Christian Bongiornohttp://christian.bongiorno.org


If you need to create new cases at runtime, you almost need to have a
scripting language to create/handle the new cases.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-05-2007
On Fri, 03 Aug 2007 22:02:21 -0000, Sideswipe
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>So, I want the nicities of an enum, but I would like to extend the
>enum list at runtime. is such a thing possible?


You probably won't like my answer, but you can compose Java source on
the fly and compile it, or compose class files on the fly.

See http://mindprod.com/jgloss/onthefly.html

Enum's are funny things. They don't let you add or remove
possibilities. They don't let you extended the methods.
There is Enumset though to play with various groups of enum constants.
see http://mindprod.com/jgloss/enumset.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
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
ENUM server for private ENUM kael UK VOIP 2 02-25-2007 11:54 AM
enum: display elements of an enum specified at runtime Jerminia Java 3 10-07-2005 10:08 PM
enum within an enum - Java 6 06-13-2005 12:51 AM
Including an enum within another enum, possible? mrhicks C Programming 2 06-10-2004 03:00 AM
How to enum an enum? Ernst Murnleitner C++ 5 11-13-2003 11:06 AM



Advertisments