元註解 Target分析

2021-10-08 11:23:57 字數 897 閱讀 5922

@target

用於描述註解的使用範圍

說明該註解可以放置在什麼地方,如介面,class類上等

使用方式:

@target()

public @inte***ce feignclient

elementtype的值
即規定註解的宣告,即限制改注釋能使用的範圍

type——介面(包括annotation,即@inte***ce)、類、列舉宣告

field——字段(包括列舉常量)宣告,@cfnotnull

method——方法宣告,如@autowired

parameter——引數宣告,如@param

constructor—— 建構函式什麼,如@constructorproperties

local_variable——區域性變數宣告,如@cfnotnull

annotation_type——注釋型別宣告,如@target

package——包宣告

type_parameter——型別引數宣告

type_use——型別的使用

原碼:

public enum elementtype

注意:當註解未指定target值時,或未被target注釋時,則說明該註解可以用於任何元素之上。

target值具有多個值的表達形式

形式1:

@target()

形式2:

@target(value = )

註解中用於 target的方法annotation

target target說明了annotation所修飾的物件範圍 annotation可被用於 packages types 類 介面 列舉 annotation型別 型別成員 方法 構造方法 成員變數 列舉值 方法引數和本地變數 如迴圈變數 catch引數 在annotation型別的宣告中使...

自定義註解 Target和 Retention說明

retention retentionpolicy.runtime target elementtype.type public inte ce test由下面的原始碼可以看出作用域是給陣列形式,表示可以多種。documented retention retentionpolicy.runtime ...

三元組相加獲得target

3sum note the solution set must not contain duplicate triplets.for example,given array s 1,0,1,2,1,4 example 1 input 1,0,1,2,1,4 a solution set is 1,0...