首页 > 文章列表 > java中@Inherited怎么使用

java中@Inherited怎么使用

java @Inherited
278 2023-05-01

说明

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 {
   ...
}

Java有哪些集合类

Java中的集合主要分为四类:

1、List列表:有序的,可重复的;

2、Queue队列:有序,可重复的;

3、Set集合:不可重复;

4、Map映射:无序,键唯一,值不唯一。