Custom annotations not accessible

Aug 7, 2010   #java 

You have written your own Java annotation and annotated a class with it but you cannot access the annotation via reflection during runtime? Most likely you have forgotten to set the right retention annotation for your own annotation. Try this:

@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    public String property();
}