Re: Unable to trace
On 5/10/13 7:43 AM, Eric Sosman wrote:
On 5/10/2013 10:26 AM, RVic wrote:
I got it. Thanks for pointing me in the right direction Eric -- the
Env enum needed the enumeration 'beta' in it.
Thanks for your help guys, I am most grateful. RVic
That's probably not the end of your problems, just a clue
about their mechanism. Adding a `beta' value to the enum means
that Env.valueOf("beta") will now return Env.beta instead of
throwing an exception. That's all fine and dandy, but what will
the rest of the code do when it encounters this new Env.beta
object? For example, there may be something like
Env env = Env.valueOf(someString);
switch (env) {
case local:
// ...
break;
case mirror:
// ...
break;
case production:
// ...
break;
}
A "beta" value will no longer cause an exception in this code,
but whatever was supposed to have been done by the switch block
will remain un-done ... (This is one reason I think it's almost
always a good idea to have a `default:' label in every switch,
even if all it does is `assert false;'.)
Or make the enum an abstract base class and have all behavior defined in
the enum itself.
For example, using them as a flyweight:
<http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/>
Switching on an enum is dangerous business, just for the reason Eric is
demonstrating. Someone adds a new enum, and switch logic no longer
handles every case. If I do happen to use an enum and have a switch
statement for it, I *always* have a default case. Sometimes that default
is "throw new UnsupportedOperationException();" Other times that default
is something that is "sensible" if an override isn't specified.