@Inherited 注解的作用@Inherited 用于放在注解上,例如
Java
运行代码复制代码
1
2
3
4
5
@Inherited
@Documented
@Target(ElementType.TYPE)
public @interface InheritedAnno {
}
当@InheritedAnno注解加在某个类A上时,假如类B继承了A,则B也会带上该注解。类继承关系中@Inherited的作用类继承关系中,子类会继承父类使用的注解中被@Inherited修饰的注解接口继承关系中@Inherited的作用接口继承关系中,子接口不会继承父接口中的任何注解,不管父接口中使用的注解有没有被@Inherited修饰类实现接口关系中@Inherited的作用类实现接口时不会继承任何接口中定义的注解