@Inherited

简介: 67347347

@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的作用
类实现接口时不会继承任何接口中定义的注解

相关文章
|
5月前
|
Java Shell Apache
|
5月前
|
存储 负载均衡 算法
|
5月前
|
前端开发 程序员
|
5月前
|
存储 Java 编译器
|
5月前
|
存储 安全 小程序
1.认识OAuth2.0
as as as ascasva
|
5月前
|
安全 Java 应用服务中间件
|
5月前
|
存储 Java 编译器
|
5月前
|
JSON 安全 Java
6.鉴权
aegheadhbdawbhwshb