Annotating enum constants
Hi, thanks for reading this post.
I expect the following code to indicate that the enum constant TRUE is annotated with the annotation @Annotated, but it does not. Does anyone see what's wrong? Thanks in advance,
Code:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public enum EnumAnnotationTest {
FALSE,
@Annotated TRUE;
private EnumAnnotationTest() {
System.out.println("Enum: "+ this.name() +", annotated? "+ this.getClass().isAnnotationPresent(Annotated.class));
}
public static void main(String[] args){}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface Annotated{}
Dan.