我有一个抽象类:
public abstract class AbstractItem
和几个具体的类:
public class ConcreteItem1 extends AbstractItem
public class ConcreteItem2 extends AbstractItem
public class ConcreteItem3 extends AbstractItem
我也有自定义注释:
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface MyAnnotation
如何强制我的ConcreteItems使用MyAnnotation? 我可以在AbstractItem-Class中以某种方式定义它吗?
答案 0 :(得分:4)
是:
将@Inherited
置于MyAnnotation
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.RUNTIME)
@Inherited
public @interface MyAnnotation
@MyAnnotation
public abstract class AbstractItem