I\'m attempting to slap two or more annotations of the same type on a single element, in this case, a method. Here\'s the approximate code that I\'m working with:
Two or more annotations of same type aren't allowed. However, you could do something like this:
public @interface Foos {
Foo[] value();
}
@Foos({@Foo(bar="one"), @Foo(bar="two")})
public void haha() {}
You'll need dedicated handling of Foos annotation in code though.
btw, I've just used this 2 hours ago to work around the same problem :)
As said by sfussenegger, this isn't possible.
The usual solution is to build an "multiple" annotation, that handles an array of the previous annotation. It is typically named the same, with an 's' suffix.
By the way, this is very used in big public projects (Hibernate for example), so it shouldn't be considered as a hack, but rather a correct solution for this need.
Depending on your needs, it could be better to allow your earlier annotation to handle multiple values.
Example:
public @interface Foo {
String[] bars();
}