I have a custom annotation:
@Target({ElementType.METHOD}) // NOTE: ElementType is METHOD
public @interface MyAnnotation {
}
I have a generic class that takes a generic bounded type:
class MyWork<T extends Annotation> {
T theAnnotation;
public ElementType checkAnnotationElementType() {
// how to get the target elementType of theAnnoation?
}
}
What I want to achieve is to get the target element type of the T theAnnotation
. For example the end result I want to achieve is:
MyWork<MyAnnotation> foo = new MyWork();
ElementType type = foo.checkAnnotationElementType(); // returns ElementType.METHOD
How can I get the element type from the generic type variable theAnnotation
?