这是应用于其他注解的注解,以提示编译器 JVM 应如何处理新注解。
当我们将此注解应用于任何其他注解时,例如:@MyCustomAnnotation
;并且 @MyCustomAnnotation
应用于任何类 MyParentClass
然后 @MyCustomAnnotation
也将可用于 MyParentClass
的所有子类。
它本质上意味着,当我们尝试在任何类 X 上查找注解 @MyCustomAnnotation
时,会查询 X 到 n 级的所有父类以获取 @MyCustomAnnotation
;如果注解存在于任何级别,则结果为真,否则为假。
请注意,默认情况下,应用于父类的注解不适用于子类。
import java.lang.annotation.Inherited; @Inherited public @interface MyCustomAnnotation { //Some other code }
日期:2020-09-17 00:10:00 来源:oir作者:oir