Koziołek
Koziołek

Reputation: 2874

How to exclude annotation element if other is set

If I have annotation like this:

public @interface MyAnnotaton{

   String className():

   Class clazz();

}

what i should do to limit setting element className if element clazz is set?

Upvotes: 2

Views: 309

Answers (2)

Óscar López
Óscar López

Reputation: 236170

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>";
}

Upvotes: 4

millimoose
millimoose

Reputation: 39990

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.

Upvotes: 1

Related Questions