public interface AnnotatedConstruct
在下面的定义中,注释A具有注释类型AT 。 如果AT是可重复的注释类型,则包含注释的类型是ATC 。
注释A 直接存在于构造C上:
通常,如果类型AT的一个注释出现在C表示的源代码中,则A被明确声明为适用于C。 如果在C上存在多个类型AT的注释,则如果AT是可重复的注释类型,则在C上隐式声明类型ATC的注释。
RuntimeVisibleAnnotations
或RuntimeVisibleParameterAnnotations
一个类文件的属性。 注释A 存在于构造C上:
value
方法的结果中的value
。 Modifier and Type | Method and Description |
---|---|
<A extends Annotation> |
getAnnotation(类<A> annotationType)
返回指定类型的这种构造的注解,如果这样的注释
存在 ,否则
null 。
|
List<? extends AnnotationMirror> |
getAnnotationMirrors()
返回
直接存在于此构造上的注释。
|
<A extends Annotation> |
getAnnotationsByType(类<A> annotationType)
返回与此
相关的结构注解。
|
List<? extends AnnotationMirror> getAnnotationMirrors()
<A extends Annotation> A getAnnotation(类<A> annotationType)
null
。
此方法返回的注释可能包含一个值为类
。 此值无法直接返回:查找和加载类(例如要使用的类加载器)所需的信息不可用,并且该类可能无法加载。 试图读取一类
通过调用返回的注释相关的方法将导致对象MirroredTypeException
,从该对应的TypeMirror
可以被提取。 类似地,尝试读取一个Class[]
元素将导致一个MirroredTypesException
。
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.
A
- 注释类型
annotationType
- 对应于注释类型的
类
对象
null
getAnnotationMirrors()
, AnnotatedElement.getAnnotation(java.lang.Class<T>)
, EnumConstantNotPresentException
, AnnotationTypeMismatchException
, IncompleteAnnotationException
, MirroredTypeException
, MirroredTypesException
<A extends Annotation> A[] getAnnotationsByType(类<A> annotationType)
getAnnotation(Class)
之间的区别在于,该方法检测其参数是否是可重复的注释类型 ,如果是,则尝试通过“查看”容器注释来查找该类型的一个或多个注释。
此方法返回的注释可能包含一个值为类
。 此值无法直接返回:查找和加载类(例如要使用的类加载器)所需的信息不可用,并且该类可能无法加载。 试图读取一类
通过调用返回的注释相关的方法将导致对象MirroredTypeException
,从该对应的TypeMirror
可以被提取。 类似地,尝试读取一个Class[]
值将导致一个MirroredTypesException
。
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation types currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation types.
A
- 注释类型
annotationType
- 对应于注释类型的
类
对象
getAnnotationMirrors()
, getAnnotation(Class)
, AnnotatedElement.getAnnotationsByType(Class)
, EnumConstantNotPresentException
, AnnotationTypeMismatchException
, IncompleteAnnotationException
, MirroredTypeException
, MirroredTypesException
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.