确保以参数为目标的Annotation具有匹配的Class<>值

时间:2015-05-05 15:45:20

标签: java annotations

假设我在一个可以

的类上有一些治疗方法(在我的情况下是方面)

我正在编写注释@ParamTreatment,如下所示

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ParamTreatment {
    Class<? extends TreaterInterface> treaterImpl();
}
public void doSomeThings(
        @ParamTreatment(treaterImpl=Treater.class) // where Treater implements TreaterInterface
        String arg) {
    //do stuff
}

我想要的是

  • TreaterInterface是参数化的。
  • Treater实现TreaterInterface的某种参数化(例如:Treater implements TreaterInterface<String>

我想声明ParamTreatment.treaterImpl,以便以下示例:

public void doSomeThings(
        @ParamTreatment(treaterImpl=Treater.class) // where Treater implements TreaterInterface<String>
        Integer arg) {
    //do stuff
}

在编译时失败,因为我声称ParamTreatment.treaterImpl某种方式看起来像Class<? extends TreaterInterface<ANNOTATION.TARGET.TYPE>> treaterImpl();

这甚至可能吗? 这是现实世界吗? 这只是幻想吗?

0 个答案:

没有答案