JAVA自定義註解

2021-08-02 07:28:20 字數 995 閱讀 2696

@target(elementtype.method)

@retention(retentionpolicy.runtime)

@documented

public @inte***ce

ignoreauth

@retention(retentionpolicy.source)   //註解僅存在於原始碼中,在class位元組碼檔案中不包含

@retention(retentionpolicy.class) // 預設的保留策略,註解會在class位元組碼檔案中存在,但執行時無法獲得,

@retention(retentionpolicy.runtime) // 註解會在class位元組碼檔案中存在,在執行時可以通過反射獲取到

@target(elementtype.type)   //介面、類、列舉、註解

@target(elementtype.field) //字段、列舉的常量

@target(elementtype.method) //方法

@target(elementtype.parameter) //方法引數

@target(elementtype.constructor) //建構函式

@target(elementtype.local_variable)//區域性變數

@target(elementtype.annotation_type)//註解

@target(elementtype.package) ///包

public

inte***ce iclientprotocolex extends iprotocol

class ipt=iclientprotocalex.class;

method mts=ipt.getmethod

();for(method

mt:mts)

Java 自定義註解Annotation

target elementtype.method retention retentionpolicy.runtime public inte ce operationtype這是乙個比較簡單的自定義註解,target 說明的是註解的作用範圍 1.constructor 用於描述構造器 2.fiel...

自定義註解

target elementtype.field retention retentionpolicy.runtime public inte ce setvalue以上就是乙個自定義的註解,下面來進行說明。target elementtype.field 表示支援該註解的程式元素,field就是屬性...

自定義註解

三個重要元註解 target 即註解的作用域,用於說明註解的使用範圍 即註解可以用在什麼地方,比如類的註解,方法註解,成員變數註解等等 elemenettype.constructor 構造器宣告 elemenettype.field 域宣告 包括 enum 例項 elemenettype.loca...