【发布时间】:2019-10-03 21:02:10
【问题描述】:
我有一个自定义注释:
@Target({ElementType.METHOD}) // NOTE: ElementType is METHOD
public @interface MyAnnotation {
}
我有一个采用泛型有界类型的泛型类:
class MyWork<T extends Annotation> {
T theAnnotation;
public ElementType checkAnnotationElementType() {
// how to get the target elementType of theAnnoation?
}
}
我想要实现的是获取T theAnnotation的目标元素类型。例如我想要达到的最终结果是:
MyWork<MyAnnotation> foo = new MyWork();
ElementType type = foo.checkAnnotationElementType(); // returns ElementType.METHOD
如何从泛型类型变量theAnnotation 中获取元素类型?
【问题讨论】:
标签: java java-annotations