2013-03-25 42 views
2

我有一个抽象类:Java:如何强制对类进行注释?

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

的顶部你的意思是,ConcreteItems应*明确*有作者,或者说,他们应该*暗示*具有相同的作者标注为AbstractItem? – sharakan 2013-03-25 16:10:55

+0

AbstractItem本身不应该有注释。子类必须有注解。 – 2013-03-25 16:14:52

回答

3

是:

@Inherited上MyAnnotation

@Target(value = ElementType.TYPE) 
@Retention(value = RetentionPolicy.RUNTIME) 
@Inherited 
public @interface MyAnnotation 

@MyAnnotation 
public abstract class AbstractItem 
相关问题