老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

java元注解@Inherited怎么用

這篇文章將為大家詳細講解有關java元注解@Inherited怎么用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

創新互聯秉承實現全網價值營銷的理念,以專業定制企業官網,成都網站設計、網站建設,小程序定制開發,網頁設計制作,手機網站開發,全網營銷推廣幫助傳統企業實現“互聯網+”轉型升級專業定制企業官網,公司注重人才、技術和管理,匯聚了一批優秀的互聯網技術人才,對客戶都以感恩的心態奉獻自己的專業和所長。

1.先看源碼文檔

/** * Indicates that an annotation type is automatically inherited. If * an Inherited meta-annotation is present on an annotation type * declaration, and the user queries the annotation type on a class * declaration, and the class declaration has no annotation for this type, * then the class's superclass will automatically be queried for the * annotation type. This process will be repeated until an annotation for this * type is found, or the top of the class hierarchy (Object) * is reached. If no superclass has an annotation for this type, then * the query will indicate that the class in question has no such annotation. * *

Note that this meta-annotation type has no effect if the annotated * type is used to annotate anything other than a class. Note also * that this meta-annotation only causes annotations to be inherited * from superclasses; annotations on implemented interfaces have no * effect. * * @author Joshua Bloch * @since 1.5 * @jls 9.6.3.3 @Inherited */@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.ANNOTATION_TYPE)public @interface Inherited {}

上述代碼注釋部分可以用谷歌翻譯大法大致意思是

表示注釋類型自動繼承。 如果在注釋類型聲明中存在繼承的元注釋,并且用戶在類聲明上查詢注釋類型,并且類聲明沒有此類型的注釋,則該類的超類將自動查詢注釋類型。 將重復此過程,直到找到此類型的注釋,或者達到類層次結構(Object)的頂部。 如果沒有超類具有此類型的注釋,則查詢將指示所討論的類沒有這樣的注釋。

請注意,如果使用注釋類型來注釋除類之外的任何內容,則此元注釋類型不起作用。 還要注意,這個元注釋只會導致從超類繼承注釋; 已實現的接口上的注釋無效。

通過上述描述可知,使用該注解的注解父類的子類可以繼承父類的注解。

2.代碼測試

2.1擁有@Inherited注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Inheritedpublic @interface InheritedTest {  String value();}

@InheritedTest("擁有Inherited")public class Person {  public void method(){  }  public void method2(){  }}

public class Student extends Person {}

測試:

public class TestInherited {  public static void main(String[] args) {    Class studentClass = Student.class;    if (studentClass.isAnnotationPresent(InheritedTest.class)){      System.out.println(studentClass.getAnnotation(InheritedTest.class).value());    }  }}

輸出:

2.2未擁有@Inherited注解

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)public @interface IsNotInherited {  String value();}

@IsNotInherited("未擁有Inherited")public class Person {  public void method(){  }  public void method2(){  }}

public class Student extends Person {}

測試:

public class TestInherited {  public static void main(String[] args) {    Class studentClass = Student.class;    if (studentClass.isAnnotationPresent(IsNotInherited.class)){      System.out.println(studentClass.getAnnotation(IsNotInherited.class).value());    }  }}

沒有輸出任何任容,由此可知未擁有@Inherited注解的注解的類的子類不會被繼承該注解。

關于“java元注解@Inherited怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。


網站欄目:java元注解@Inherited怎么用
轉載來于:http://www.xueling.net.cn/article/jciipj.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 国产九九热| 亚洲av色香蕉一区二区三区老师 | 欧美破苞系列二十三 | 久久久久国产亚洲AV麻豆 | 99精品综合加勒比在线观 | 东方欧美亚洲色图 | 99热这里只有精品5 曼谷av女郎 | 欧美不卡区 | 毛片真人毛毛片毛片 | 办公室撕开奶罩揉吮奶头H文 | 豪放女大兵免费看 | 精品一区二区中文字幕 | 久久福利一区 | 久久免费大视频 | 91pro在线观看| 美女搞久久 | 午夜精品久久久久久久99热 | 久久久久久亚洲AV无码蜜芽 | 亚洲AV无码潮喷在线观看 | 99久久欧美日韩国产二区 | 国产高清av | 欧美、另类亚洲日本一区二区 | 希岛爱理aⅴ在线中文字幕 美景之屋5在线观看 | 四库成人免费视频 | 一本大道香蕉久中文在线播放 | 亚洲精品视频一区 | 男人和女人高潮免费网站 | 精品亚洲国产成人A片在线观看 | 久久久精品视频网站 | 亚洲人和日本人hd | 成人影院免费942cm | 狠狠热免费视频 | 性高潮久久久久 | 99热久久精里都是精品6 | 日韩a一区二区 | 男人操女人视频免费看 | 94欧美setu| 不卡一区二区在线 | 51社区在线永久免费视频 | 九九专区一线二线三线 | 9l亚洲国产成人精品一区二三 |