Enum with annotations
807580Aug 16 2010 — edited Aug 16 2010Hi,
I using the enum with annotations, for that i have following classes :-
1) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface intValue {
int numericValue();
}
2) public enum Numbers {
@intValue(numericValue = 1)
ONE,
@intValue(numericValue = 2)
TWO,
@intValue(numericValue = 3)
THREE;
int format;
private Numbers(){
}
private Numbers(int format) {
this.format = format;
}
public int getValue() {
return this.format;
}
}
3) public class AnnotationEnumTest {
public static void main(String args[]){
try{
String field = Numbers.ONE.toString();
System.out.println("the final value is:::"+Numbers.THREE.getValue());
}catch(Exception e){
e.printStackTrace();
}
}
Here in the Main class i need to get the nuericValue "3" as supposed to "THREE", hence i tried with Numbers.THREE.getValue() which is returning "0". If i use Numbers.THREE.toString() i will get the "THREE" which i dont need . I need to get the value "3"? How do i get it?
Thanks in advance.
}