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 / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Sideswipe - 03 Aug 2007 23:02 GMT
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
Piotr Kobzda - 03 Aug 2007 23:19 GMT
> So, I want the nicities of an enum, but I would like to extend the
> enum list at runtime. is such a thing possible?
[quoted text clipped - 18 lines]
> 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
Daniel Pitts - 03 Aug 2007 23:38 GMT
> So, I want the nicities of an enum, but I would like to extend the
> enum list at runtime. is such a thing possible?
[quoted text clipped - 21 lines]
>
> 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.
Roedy Green - 05 Aug 2007 15:54 GMT
On Fri, 03 Aug 2007 22:02:21 -0000, Sideswipe
<christian.bongiorno@gmail.com> 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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



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



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