This question already has an answer here:
Is there a way that I can give an annotation an method as an input. Then use the value returned from it to pass to the annotation ?
public String fnc(String value){
//do something
return ret;
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface MAnon{
String cond = fnc(cond);
}
@MAnon(fnc("Something")) //does not work
@MAnon("Something")
public void foo(){ ... }
public void bar(){
//reflection call
MAnon a = ...getDeclaredAnnotations()[0]
String foo = a; //may not be the same as what is typed
}
Aucun commentaire:
Enregistrer un commentaire