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 [...]

programming | No Comments

 

April 2008
M T W T F S S
    May »
 123456
78910111213
14151617181920
21222324252627
282930  

Categories

Archives

Tags