src/share/classes/java/lang/reflect/AnnotatedElement.java

Print this page




  74  * {@link java.lang.annotation.IncompleteAnnotationException}.
  75  *
  76  * @see java.lang.EnumConstantNotPresentException
  77  * @see java.lang.TypeNotPresentException
  78  * @see java.lang.annotation.AnnotationFormatError
  79  * @see java.lang.annotation.AnnotationTypeMismatchException
  80  * @see java.lang.annotation.IncompleteAnnotationException
  81  * @see java.lang.annotation.InvalidContainerAnnotationError
  82  * @since 1.5
  83  * @author Josh Bloch
  84  */
  85 public interface AnnotatedElement {
  86     /**
  87      * Returns true if an annotation for the specified type
  88      * is present on this element, else false.  This method
  89      * is designed primarily for convenient access to marker annotations.
  90      *
  91      * <p>The truth value returned by this method is equivalent to:
  92      * {@code getAnnotation(annotationClass) != null}
  93      *



  94      * @param annotationClass the Class object corresponding to the
  95      *        annotation type
  96      * @return true if an annotation for the specified annotation
  97      *     type is present on this element, else false
  98      * @throws NullPointerException if the given annotation class is null
  99      * @since 1.5
 100      */
 101      boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);


 102 
 103    /**
 104      * Returns this element's annotation for the specified type if
 105      * such an annotation is present, else null.
 106      *
 107      * @param annotationClass the Class object corresponding to the
 108      *        annotation type
 109      * @return this element's annotation for the specified annotation type if
 110      *     present on this element, else null
 111      * @throws NullPointerException if the given annotation class is null
 112      * @since 1.5
 113      */
 114     <T extends Annotation> T getAnnotation(Class<T> annotationClass);
 115 
 116     /**
 117      * Returns an array of all this element's annotations for the
 118      * specified type if one or more of such annotation is present,
 119      * else an array of length zero.
 120      *
 121      * The caller of this method is free to modify the returned array;




  74  * {@link java.lang.annotation.IncompleteAnnotationException}.
  75  *
  76  * @see java.lang.EnumConstantNotPresentException
  77  * @see java.lang.TypeNotPresentException
  78  * @see java.lang.annotation.AnnotationFormatError
  79  * @see java.lang.annotation.AnnotationTypeMismatchException
  80  * @see java.lang.annotation.IncompleteAnnotationException
  81  * @see java.lang.annotation.InvalidContainerAnnotationError
  82  * @since 1.5
  83  * @author Josh Bloch
  84  */
  85 public interface AnnotatedElement {
  86     /**
  87      * Returns true if an annotation for the specified type
  88      * is present on this element, else false.  This method
  89      * is designed primarily for convenient access to marker annotations.
  90      *
  91      * <p>The truth value returned by this method is equivalent to:
  92      * {@code getAnnotation(annotationClass) != null}
  93      *
  94      * <p>The body of the default method is specified to be the code
  95      * above.
  96      *
  97      * @param annotationClass the Class object corresponding to the
  98      *        annotation type
  99      * @return true if an annotation for the specified annotation
 100      *     type is present on this element, else false
 101      * @throws NullPointerException if the given annotation class is null
 102      * @since 1.5
 103      */
 104     default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
 105         return getAnnotation(annotationClass) != null;
 106     }
 107 
 108    /**
 109      * Returns this element's annotation for the specified type if
 110      * such an annotation is present, else null.
 111      *
 112      * @param annotationClass the Class object corresponding to the
 113      *        annotation type
 114      * @return this element's annotation for the specified annotation type if
 115      *     present on this element, else null
 116      * @throws NullPointerException if the given annotation class is null
 117      * @since 1.5
 118      */
 119     <T extends Annotation> T getAnnotation(Class<T> annotationClass);
 120 
 121     /**
 122      * Returns an array of all this element's annotations for the
 123      * specified type if one or more of such annotation is present,
 124      * else an array of length zero.
 125      *
 126      * The caller of this method is free to modify the returned array;