Source Home >> Java Source 1.6.0 >> java.lang.reflect.AnnotatedElement V 0.09
  • 01/*
  • 02 * @(#)AnnotatedElement.java 1.5 05/11/17
  • 03 *
  • 04 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  • 05 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  • 06 */
  • 07
  • 08package java.lang.reflect;
  • 09
  • 10import java.lang.annotation.Annotation;
  • 11
  • 12/**
  • 13 * Represents an annotated element of the program currently running in this
  • 14 * VM. This interface allows annotations to be read reflectively. All
  • 15 * annotations returned by methods in this interface are immutable and
  • 16 * serializable. It is permissible for the caller to modify the
  • 17 * arrays returned by accessors for array-valued enum members; it will
  • 18 * have no affect on the arrays returned to other callers.
  • 19 *
  • 20 * <p>If an annotation returned by a method in this interface contains
  • 21 * (directly or indirectly) a {@link Class}-valued member referring to
  • 22 * a class that is not accessible in this VM, attempting to read the class
  • 23 * by calling the relevant Class-returning method on the returned annotation
  • 24 * will result in a {@link TypeNotPresentException}.
  • 25 *
  • 26 * <p>Similarly, attempting to read an enum-valued member will result in
  • 27 * a {@link EnumConstantNotPresentException} if the enum constant in the
  • 28 * annotation is no longer present in the enum type.
  • 29 *
  • 30 * <p>Finally, Attempting to read a member whose definition has evolved
  • 31 * incompatibly will result in a {@link
  • 32 * java.lang.annotation.AnnotationTypeMismatchException} or an
  • 33 * {@link java.lang.annotation.IncompleteAnnotationException}.
  • 34 *
  • 35 * @since 1.5
  • 36 * @author Josh Bloch
  • 37 */
  • 38public interface AnnotatedElement {
  • 39 /**
  • 40 * Returns true if an annotation for the specified type
  • 41 * is present on this element, else false. This method
  • 42 * is designed primarily for convenient access to marker annotations.
  • 43 *
  • 44 * @param annotationClass the Class object corresponding to the
  • 45 * annotation type
  • 46 * @return true if an annotation for the specified annotation
  • 47 * type is present on this element, else false
  • 48 * @throws NullPointerException if the given annotation class is null
  • 49 * @since 1.5
  • 50 */
  • 51 boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
  • 52
  • 53 /**
  • 54 * Returns this element's annotation for the specified type if
  • 55 * such an annotation is present, else null.
  • 56 *
  • 57 * @param annotationClass the Class object corresponding to the
  • 58 * annotation type
  • 59 * @return this element's annotation for the specified annotation type if
  • 60 * present on this element, else null
  • 61 * @throws NullPointerException if the given annotation class is null
  • 62 * @since 1.5
  • 63 */
  • 64 <T extends Annotation> T getAnnotation(Class<T> annotationClass);
  • 65
  • 66 /**
  • 67 * Returns all annotations present on this element. (Returns an array
  • 68 * of length zero if this element has no annotations.) The caller of
  • 69 * this method is free to modify the returned array; it will have no
  • 70 * effect on the arrays returned to other callers.
  • 71 *
  • 72 * @return all annotations present on this element
  • 73 * @since 1.5
  • 74 */
  • 75 Annotation[] getAnnotations();
  • 76
  • 77 /**
  • 78 * Returns all annotations that are directly present on this
  • 79 * element. Unlike the other methods in this interface, this method
  • 80 * ignores inherited annotations. (Returns an array of length zero if
  • 81 * no annotations are directly present on this element.) The caller of
  • 82 * this method is free to modify the returned array; it will have no
  • 83 * effect on the arrays returned to other callers.
  • 84 *
  • 85 * @return All annotations directly present on this element
  • 86 * @since 1.5
  • 87 */
  • 88 Annotation[] getDeclaredAnnotations();
  • 89}

文件:AnnotatedElement.java
包名:java.lang.reflect
类名:AnnotatedElement
继承:
接口: