首页 > 文章列表 > java中@Inherited是什么?

java中@Inherited是什么?

java @Inherited
457 2022-08-06

说明

1、标记表明某个标记的类型被继承,@inherited修饰的annotation类型被用于class,annotation被用于class的子类,@inheritedannotation类型被标记的class的子类。

作用

2、允许子类继承父类注释。

实例

MyParentClass在用的注释标记是@Inherited,子类可以继承注释信息。

java.lang.annotation.Inherited
@Inherited
public @interface MyCustomAnnotation {
}
 
@MyCustomAnnotation
public class MyParentClass {
  ...
}
 
public class MyChildClass extends MyParentClass {
   ...
}

本教程操作环境:windows7系统、java10版,DELL G3电脑。