Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1239

Re: Dynamic enums

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.help
Subject Re: Dynamic enums
Date Tue, 11 Oct 2011 22:05:40 -0400
Organization A noiseless patient Spider
Lines 48
Message-ID <j72sn7$cl$1@dont-email.me> (permalink)
References <4e94eeb1$0$16274$9a566e8b@news.aliant.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Wed, 12 Oct 2011 02:06:31 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="f8igmItKsWs6nM5YanFxAA"; logging-data="405"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7TNjgTpoR5TUwh4fexqN5"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
In-Reply-To <4e94eeb1$0$16274$9a566e8b@news.aliant.net>
Cancel-Lock sha1:fL8vlA8YP7IGa4/jIjCBDvL+zP4=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:1239

Show key headers only | View raw


On 10/11/2011 9:34 PM, Linus Flustillbe wrote:
> Let's say I have an ENUM defined as
>
> public enum xxx {
>    A, B, C, D, E
> }
>
> Now here's my question.
> Let's say I have a table called foobar which has the following rows
>
> A  1
> B  2
> C  3
> D  4
> E  5
>
> My code is written and is working great.  The enum xxx is used as a
> lookup on the foobar table.  If I add a row to foobar like
>
> F  6
>
> I need to add another enum to the xxx enum and rebuild my project.
>
> So my question is, is there something like a dynamic enun:  by this
> could I call a method on the xxx enum like
>
> xxx.addnew("F") that would make F a valid enum of xxx and not have to
> rebuild my project?

     No.  The names of enum constants are compile-time artifacts,
just like the names of local variables.  At run-time, all such
things have disappeared (well, they may survive in ancillary debug
data, but the C language has no access to such things).

     Besides, what use could you make of such a dynamic enum, even
if you could create it?  If there's a `switch' with cases for
A,B,C,D,E, it won't magically acquire a new case for F.  If you've
got an array of the values A,B,C,D,E that you traverse from time to
time, the array won't magically lengthen and acquire an F-valued
element.  What do you expect to be able to do with F, given that the
code as written never mentions the identifier `F' at all?  (Worse,
what do you expect to do if the code *does* use `F', but in some
completely different context?  Does creating the dynamic enum `F'
cause a retroactive compilation failure?)

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Dynamic enums Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-12 01:34 +0000
  Re: Dynamic enums Lew <lewbloch@gmail.com> - 2011-10-11 19:03 -0700
  Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-11 22:05 -0400
    Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-11 22:11 -0400
      Re: Dynamic enums Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-12 06:02 +0000
        Re: Dynamic enums markspace <-@.> - 2011-10-11 23:44 -0700
        Re: Dynamic enums Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-12 07:58 -0400
          Re: Dynamic enums markspace <-@.> - 2011-10-12 07:46 -0700
  Re: Dynamic enums markspace <-@.> - 2011-10-11 19:32 -0700
  Re: Dynamic enums Roedy Green <see_website@mindprod.com.invalid> - 2011-10-12 07:02 -0700

csiph-web