I want to create a custom annotation (using Java) which would accept other annotations as parameter, something like:
public @interface ExclusiveOr {
Anno
Depending on the reason why you would want to specify other annotations there are multiple solutions:
Probably not what you meant in your question, but if you want to specify multiple instances of a single annotation type it's certainly possible:
public @interface Test {
SomeAnnotation[] value();
}
If you do not need to specify any parameters on the individual annotations you can just user their class objects instead of instances.
public @interface Test {
Class extends Annotation>[] value();
}
But an enum would of course also do the trick in most situations.
If the set of possible annotation types you want to use is limited, you can create a separate parameter for each one.
public @interface Test {
SomeAnnotation[] somes() default { };
ThisAnnotation[] thiss() default { };
ThatAnnotation[] thats() default { };
}
Giving a default value to each member makes it possible to only specify arrays for the types you need.