> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to java...@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
An controversial solution might be to dispatch from the Enum to
elsewhere:
interface SuitDescriptor {
String getDescription(Suit suit);
};
enum Suit {
Diamonds, Hearts, Clubs, Spades;
private static SuitDescriptor descriptor;
public static void setSuitDescriptor(SuitDescriptor descriptor) {
Suit.descriptor = descriptor;
}
public String getDescription() {
if(descriptor == null)
throw new IllegalStateException("Description callback not
specified!");
return descriptor.getDescription(this);
}
}
It's really a case where extension methods would come in handy, but
Java doesn't have that yet.
/Casper
On Mar 23, 11:36 pm, Alexey Zinger <inline_f...@yahoo.com> wrote:
> If you need to be able to define a set of singletons from outside the JVM (database, config file, etc.), they're not really enums anymore. By definition, they'll have to be dynamically instantiated and you won't be able to refer to them by any kind of identifier the Java compiler will understand. They'll have a number of aspects in common with enums, but not that cruicial aspect of compiler being aware of the full set of enums of any particular type. Is there then a good reason to convert what you already have and tested and presumably working to something based on Java 5 enum syntax?
>
> Note, as someone pointed out, that if you can do away with the requirement of defining a set of enums outside your Java code, then yeah, you can load descriptors and other stuff from outside, but you'd be faced with 2 bad (in my opinion choices): load that info at class initialization time, or lazily. The problem with the former is that it's really not nice to crash during class loading because it can manifest itself and take down parts of systems you never expected. The problem with the latter is that once you've initialized, unless you immediately do a sanity check invocation to make sure all attribute have loaded, you expose yourself to getting inconsistent values or crashing later on at an unknown time.
>
> Alexey
> 2001 Honda CBR600F4i (CCS)
> 2002 Suzuki Bandit 1200S
> 1992 Kawasaki EX500http://azinger.blogspot.comhttp://bsheet.sourceforge.nethttp://wcollage.sourceforge.net
>
> ________________________________
> From: Mike Calmus <mcal...@nyx.net>