Most visited

Recently visited

Added in API level 1

AnnotatedElement

public interface AnnotatedElement

java.lang.reflect.AnnotatedElement
Known Indirect Subclasses


表示当前在此VM中运行的程序的注释元素。 该界面允许反射地读取注释。 这个接口中的方法返回的所有注释都是不可变的,可序列化的。 允许调用者修改访问器为阵列值枚举成员返回的数组; 它将不会影响返回给其他调用者的数组。

如果通过一种在此接口返回的注释包含(直接或间接) Class -valued构件指的是类不在这个VM访问,试图通过调用返回的注释相关的类返回方法读取类将导致 TypeNotPresentException

同样,如果注释中的枚举常量不再存在于枚举类型中,试图读取枚举值成员将导致 EnumConstantNotPresentException

最后,试图读取其定义不一致的成员将导致 AnnotationTypeMismatchExceptionIncompleteAnnotationException

也可以看看:

摘要(Summary)

公共方法(Public methods)

abstract <T extends Annotation> T getAnnotation(Class<T> annotationClass)

如果存在这样的注释,则返回指定类型的此元素的注释,否则返回null。

abstract Annotation[] getAnnotations()

返回此元素上的所有注释。

default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass)

返回 this元素(其类别为 annotationClass的注释的关联列表,如果未找到任何元素,则 annotationClass空数组。

default <T extends Annotation> Annotation getDeclaredAnnotation(Class<T> annotationClass)

返回 this元素上直接存在的注释,其类别为 annotationClassnull如果未找到任何内容。

abstract Annotation[] getDeclaredAnnotations()

返回直接出现在此元素上的所有注释。

default <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass)

返回 this元素(其类别为 annotationClass上的注释的直接或间接存在列表,如果没有找到,则 annotationClass一个空数组。

default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)

如果此元素上存在指定类型的注释,则返回true,否则返回false。

公共方法(Public methods)

getAnnotation

Added in API level 1
T getAnnotation (Class<T> annotationClass)

如果存在这样的注释,则返回指定类型的此元素的注释,否则返回null。

参数(Parameters)
annotationClass Class: the Class object corresponding to the annotation type
返回(Returns)
T this element's annotation for the specified annotation type if present on this element, else null
抛出异常(Throws)
NullPointerException if the given annotation class is null

getAnnotations

Added in API level 1
Annotation[] getAnnotations ()

返回此元素上的所有注释。 (如果此元素没有注释,则返回长度为零的数组。)此方法的调用方可自由修改返回的数组; 它将不会影响返回给其他调用者的数组。

返回(Returns)
Annotation[] all annotations present on this element

getAnnotationsByType

Added in API level 24
T[] getAnnotationsByType (Class<T> annotationClass)

返回 this元素(其类别为 annotationClass的注释的关联列表,如果没有找到任何元素,则 annotationClass一个空数组。

参数(Parameters)
annotationClass Class
返回(Returns)
T[]

getDeclaredAnnotation

Added in API level 24
Annotation getDeclaredAnnotation (Class<T> annotationClass)

返回 this元素上直接存在的注释,其类别为 annotationClassnull如果未找到任何内容。

参数(Parameters)
annotationClass Class
返回(Returns)
Annotation

getDeclaredAnnotations

Added in API level 1
Annotation[] getDeclaredAnnotations ()

返回直接出现在此元素上的所有注释。 与此接口中的其他方法不同,此方法会忽略继承的注释。 (如果此元素上没有注释,则返回长度为零的数组。)此方法的调用方可自由修改返回的数组; 它将不会影响返回给其他调用者的数组。

返回(Returns)
Annotation[] All annotations directly present on this element

getDeclaredAnnotationsByType

Added in API level 24
T[] getDeclaredAnnotationsByType (Class<T> annotationClass)

返回 this元素(其类别为 annotationClass上的注释的直接或间接存在列表,如果没有找到,则 annotationClass空数组。

参数(Parameters)
annotationClass Class
返回(Returns)
T[]

isAnnotationPresent

Added in API level 1
boolean isAnnotationPresent (Class<? extends Annotation> annotationClass)

如果此元素上存在指定类型的注释,则返回true,否则返回false。 此方法主要用于方便地访问标记注释。

参数(Parameters)
annotationClass Class: the Class object corresponding to the annotation type
返回(Returns)
boolean true if an annotation for the specified annotation type is present on this element, else false
抛出异常(Throws)
NullPointerException if the given annotation class is null

Hooray!