@CustomAnnotation(chat = false)
public class Controller {
@CustomAnnotation(login = true)
protected String getResult() {
// function body
}
protected String getMark() {
// function body
}
}
Code for CustomAnnotation:
@Documented
@Target({ ElementType.METHOD, ElementType.TYPE })
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {
boolean login() default false;
boolean chat() default true;
}
Here, the CustomAnnotation can be applied to both class and its methods. How to find the declared annotation for the function getResult(). Assuming method is "getResult", method.getAnnotation(CustomAnnotation.class) will return [@com.xyz.CustomAnnotation(chat=true, login=true)] but I want [@com.xyz.CustomAnnotation(chat=false, login=true)] as class is also annotated with CustomAnnotation.
I want all the annotation attribute at once.
Aucun commentaire:
Enregistrer un commentaire