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

 

March 2010
M T W T F S S
« Jul    
1234567
891011121314
15161718192021
22232425262728
293031  

Categories

Archives

Tags