@Inherited

Summary::如果某个注解被@Inherited注解了,那么拥有这个注解的类的子类会继承这个注解

样例

public class InheritedTest {  
    @Inherited  
    @Retention(RetentionPolicy.RUNTIME)  
    public @interface InheritedAnnotation {  
    }  
    @InheritedAnnotation  
    public class Parent {    }  
    public class Child extends Parent {    }  
    public static void main(String[] args) {  
        InheritedTest test = new InheritedTest();  
        Child child = test.new Child();  
        //通过反射获取子类的注解  
        System.out.println("child class Annotations" + child.getClass().getAnnotation(InheritedAnnotation.class));  
    }  
}