Archives for April 25th, 2008
Binding data to Java enums…
Friday, April 25th, 2008
Paul Stovell blogged about binding data to enums in C#. Here is how I would implement this technique in Java….
First, an annotation that I will use to bind data to my enum
@Target(Element.FIELD)
@Retention(RententionPolicy.RUNTIME)
public @interface Config {
String name();
String alias();
}
Then, here is my enum
public enum Role {
@Config(name="James Bond", alias = "Agent 007")
AGENT;
// static attribute that will allow us [...]