I have below annotation.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}
This works as well - You can fetch annotation information using reflection on the class.
Annotation anno = MyClass.class.getAnnotation(MyAnnotation.class);
Or
Annotation anno = MyClass.class.getDeclaredMethod("somethod").getAnnotation(MyAnnotation.class);
This works only if your annotation is available at runtime, which you have declared correctly.
@Retention(RetentionPolicy.RUNTIME)