Spec-Zone .ru
спецификации, руководства, описания, API
|
public interface AnnotatedElement
The getAnnotationsByType(Class)
and getDeclaredAnnotationsByType(Class)
methods support multiple
annotations of the same type on an element. If the argument to either method
is a repeatable annotation type (JLS 9.6), then the method will "look
through" a container annotation (JLS 9.7) which was generated at
compile-time to wrap multiple annotations of the argument type.
The terms directly present and present are used throughout this interface to describe precisely which annotations are returned by methods:
get[Declared]Annotation(Class<T>)
or
get[Declared]Annotations()
, the attribute contains A.
get[Declared]AnnotationsByType(Class<T>)
, the
attribute either contains A or, if the type of A is repeatable, contains
exactly one annotation whose value element contains A and whose type is the
containing annotation type of A's type (JLS 9.6).
If an annotation returned by a method in this interface contains
(directly or indirectly) a Class
-valued member referring to
a class that is not accessible in this VM, attempting to read the class
by calling the relevant Class-returning method on the returned annotation
will result in a TypeNotPresentException
.
Similarly, attempting to read an enum-valued member will result in
a EnumConstantNotPresentException
if the enum constant in the
annotation is no longer present in the enum type.
Attempting to read annotations of a repeatable annotation type T
that are contained in an annotation whose type is not, in fact, the
containing annotation type of T, will result in an AnnotationFormatError
.
Finally, attempting to read a member whose definition has evolved
incompatibly will result in a AnnotationTypeMismatchException
or an
IncompleteAnnotationException
.
Modifier and Type | Method and Description |
---|---|
<T extends Annotation> |
getAnnotation(Class<T> annotationClass)
Returns this element's annotation for the specified type if
such an annotation is present, else null.
|
Annotation[] |
getAnnotations()
Returns annotations that are present on this element.
|
<T extends Annotation> |
getAnnotationsByType(Class<T> annotationClass)
Returns annotations that are present on this element.
|
<T extends Annotation> |
getDeclaredAnnotation(Class<T> annotationClass)
Returns this element's annotation for the specified type if
such an annotation is present, else null.
|
Annotation[] |
getDeclaredAnnotations()
Returns annotations that are directly present on this element.
|
<T extends Annotation> |
getDeclaredAnnotationsByType(Class<T> annotationClass)
Returns annotations that are directly present on this element.
|
default boolean |
isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type
is present on this element, else false.
|
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
The truth value returned by this method is equivalent to:
getAnnotation(annotationClass) != null
The body of the default method is specified to be the code above.
annotationClass
- the Class object corresponding to the
annotation typeNullPointerException
- if the given annotation class is null<T extends Annotation> T getAnnotation(Class<T> annotationClass)
annotationClass
- the Class object corresponding to the
annotation typeNullPointerException
- if the given annotation class is null<T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass)
getAnnotation(Class)
is that this method detects if its argument is a repeatable
annotation type (JLS 9.6), and if so, attempts to find one or
more annotations of that type by "looking through" a container
annotation.
The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.annotationClass
- the Class object corresponding to the
annotation typeNullPointerException
- if the given annotation class is nullAnnotation[] getAnnotations()
<T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass)
annotationClass
- the Class object corresponding to the
annotation typeNullPointerException
- if the given annotation class is null<T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass)
getDeclaredAnnotation(Class)
is that this method detects if its
argument is a repeatable annotation type (JLS 9.6), and if so,
attempts to find one or more annotations of that type by "looking
through" a container annotation.
The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.annotationClass
- the Class object corresponding to the
annotation typeNullPointerException
- if the given annotation class is nullAnnotation[] getDeclaredAnnotations()
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, 2013, Oracle and/or its affiliates. All rights reserved.
DRAFT ea-b92