How to exclude annotation element if other is set
If I have annotation like this:
public @interface MyAnnotaton{
String className():
Class clazz();
}
what i sh开发者_StackOverflow中文版ould do to limit setting element className if element clazz is set?
Provide a default value for one of the elements, and in your AnnotationProcessor code the necessary logic to detect which element should be processed
public @interface MyAnnotation {
Class clazz();
String className() default "<none>";
}
I'd wager to say this is impossible – annotations aren't executable code and do not intrinsically have any logic. Either settle on one of the two, or pick which one takes precedence and document the annotation accordingly.
精彩评论