public interface AnnotatedElement 
 
| java.lang.reflect.AnnotatedElement | 
|  Known Indirect Subclasses | 
表示当前在此VM中运行的程序的注释元素。 该界面允许反射地读取注释。 这个接口中的方法返回的所有注释都是不可变的,可序列化的。 允许调用者修改访问器为阵列值枚举成员返回的数组; 它将不会影响返回给其他调用者的数组。
如果通过一种在此接口返回的注释包含(直接或间接) Class -valued构件指的是类不在这个VM访问,试图通过调用返回的注释相关的类返回方法读取类将导致 TypeNotPresentException 。
同样,如果注释中的枚举常量不再存在于枚举类型中,试图读取枚举值成员将导致 EnumConstantNotPresentException 。
最后,试图读取其定义不一致的成员将导致 AnnotationTypeMismatchException或 IncompleteAnnotationException 。
也可以看看:
| Public methods | |
|---|---|
|  abstract <T extends Annotation> T |  getAnnotation(Class<T> annotationClass) 如果存在这样的注释,则返回指定类型的此元素的注释,否则返回null。 | 
|  abstract Annotation[] |  getAnnotations() 返回此元素上的所有注释。 | 
|  default <T extends Annotation> T[] |  getAnnotationsByType(Class<T> annotationClass) 返回  | 
|  default <T extends Annotation> Annotation |  getDeclaredAnnotation(Class<T> annotationClass) 返回  | 
|  abstract Annotation[] |  getDeclaredAnnotations() 返回直接出现在此元素上的所有注释。 | 
|  default <T extends Annotation> T[] |  getDeclaredAnnotationsByType(Class<T> annotationClass) 返回  | 
|  default boolean |  isAnnotationPresent(Class<? extends Annotation> annotationClass) 如果此元素上存在指定类型的注释,则返回true,否则返回false。 | 
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 | 
Annotation[] getAnnotations ()
返回此元素上的所有注释。 (如果此元素没有注释,则返回长度为零的数组。)此方法的调用方可自由修改返回的数组; 它将不会影响返回给其他调用者的数组。
| Returns | |
|---|---|
| Annotation[] | all annotations present on this element | 
T[] getAnnotationsByType (Class<T> annotationClass)
返回 this元素(其类别为 annotationClass的注释的关联列表,如果没有找到任何元素,则 annotationClass一个空数组。
| Parameters | |
|---|---|
| annotationClass | Class | 
| Returns | |
|---|---|
| T[] | |
Annotation getDeclaredAnnotation (Class<T> annotationClass)
返回 this元素上直接存在的注释,其类别为 annotationClass或 null如果未找到任何内容。
| Parameters | |
|---|---|
| annotationClass | Class | 
| Returns | |
|---|---|
| Annotation | |
Annotation[] getDeclaredAnnotations ()
返回直接出现在此元素上的所有注释。 与此接口中的其他方法不同,此方法会忽略继承的注释。 (如果此元素上没有注释,则返回长度为零的数组。)此方法的调用方可自由修改返回的数组; 它将不会影响返回给其他调用者的数组。
| Returns | |
|---|---|
| Annotation[] | All annotations directly present on this element | 
T[] getDeclaredAnnotationsByType (Class<T> annotationClass)
返回 this元素(其类别为 annotationClass上的注释的直接或间接存在列表,如果没有找到,则 annotationClass空数组。
| Parameters | |
|---|---|
| annotationClass | Class | 
| Returns | |
|---|---|
| T[] | |
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 |