Java里面有四种元注解,@Inherited便是其中之一,其作用在java文档中写的很清楚了:
表明一个注解是可以被继承的。如果一个注解A被@inherited标注,那么当调用反射api查询一个类是否被A标注不仅仅会看这个类有没有A注解,同时会看A的父类是否有A注解,直到找到A注解或者到达了顶层父类。
这个特性可以理解为子类会继承父类的被@Inherited修饰过的注解。
另外这个效果仅仅作用在类上,对接口无效。
wx636dc453ed367 博主文章分类:java ©著作权
Java里面有四种元注解,@Inherited便是其中之一,其作用在java文档中写的很清楚了:
表明一个注解是可以被继承的。如果一个注解A被@inherited标注,那么当调用反射api查询一个类是否被A标注不仅仅会看这个类有没有A注解,同时会看A的父类是否有A注解,直到找到A注解或者到达了顶层父类。
这个特性可以理解为子类会继承父类的被@Inherited修饰过的注解。
另外这个效果仅仅作用在类上,对接口无效。
下一篇:【redis】Key 命名
1. 元注解的基本介绍JDK 的元 Annotation 用于修饰其他 Annotation元注解: 本身作用不大,看源码时,可以知道是干什么
注解Java注解也称Java标注,是jdk1.5(5.0)后的新特征。Java语言中的类、方法、
学习Java以来经常看到关于注解的使用,以前总是感觉自己用不到不太关注,总是
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M