类 AnnotationUtils


  • public abstract class AnnotationUtils
    extends Object
    General utility methods for working with annotations, handling meta-annotations, bridge methods (which the compiler generates for generic declarations) as well as super methods (for optional annotation inheritance).

    Note that most of the features of this class are not provided by the JDK's introspection facilities themselves.

    As a general rule for runtime-retained application annotations (e.g. for transaction control, authorization, or service exposure), always use the lookup methods on this class (e.g. findAnnotation(Method, Class) or getAnnotation(Method, Class)) instead of the plain annotation lookup methods in the JDK. You can still explicitly choose between a get lookup on the given class level only (getAnnotation(Method, Class)) and a find lookup in the entire inheritance hierarchy of the given method (findAnnotation(Method, Class)).

    Terminology

    The terms directly present, indirectly present, and present have the same meanings as defined in the class-level javadoc for AnnotatedElement (in Java 8).

    An annotation is meta-present on an element if the annotation is declared as a meta-annotation on some other annotation which is present on the element. Annotation A is meta-present on another annotation if A is either directly present or meta-present on the other annotation.

    Meta-annotation Support

    Most find*() methods and some get*() methods in this class provide support for finding annotations used as meta-annotations. Consult the javadoc for each method in this class for details. For fine-grained support for meta-annotations with attribute overrides in composed annotations, consider using AnnotatedElementUtils's more specific methods instead.

    Attribute Aliases

    All public methods in this class that return annotations, arrays of annotations, or AnnotationAttributes transparently support attribute aliases configured via @AliasFor. Consult the various synthesizeAnnotation*(..) methods for details.

    Search Scope

    The search algorithms used by methods in this class stop searching for an annotation once the first annotation of the specified type has been found. As a consequence, additional annotations of the specified type will be silently ignored.

    从以下版本开始:
    2.0
    作者:
    Rob Harrop, Juergen Hoeller, Sam Brannen, Mark Fisher, Chris Beams, Phillip Webb, Oleg Zhurakousky
    另请参阅:
    AliasFor, AnnotationAttributes, AnnotatedElementUtils, BridgeMethodResolver, AnnotatedElement.getAnnotations(), AnnotatedElement.getAnnotation(Class), AnnotatedElement.getDeclaredAnnotations()