Reputation:
Lets suppose I have two annotation classes: Annotation1 and Annotation2.
and I have a method:
public void doSomethingWithAnnodation(Class<?> annotationClass) {
...
}
The problem with this method is that any class can be passed as argument. Can I make compiler to allow only annotation classes (Annotation1 and Annotation2)?
Upvotes: 1
Views: 49
Reputation: 46315
You can specify java.lang.annotation.Annotation
, which all annotations implement, as an upper bound:
public void doSomethingWithAnnotation(Class<? extends Annotation> annotationClass) {
//...
}
Upvotes: 3