Interface JAnnotation

  • All Superinterfaces:
    All Known Subinterfaces:
    All Known Implementing Classes:

    public interface JAnnotation
    extends JElement

    Represents a metadata that is associated with a particular JElement. Note that JAnnoations are JElements, which means that they themselves can have annotations, and can be treated as nodes in a JAM hierarchy.

    Annotations can be simple or complex. Values of simple annotations can be retrieved via the various get...Value() methods. Complex attributes can be navigated via the getAnnotations() method which exposes nested attributes (which may in turn be either simple or complex.

    • Method Detail

      • getSimpleName

        java.lang.String getSimpleName()
        Description copied from interface: JElement

        Returns a simple name of this abstraction. The exact format of the name depends on the particular abstraction (see javadoc). Please refer to the JAM package documentation for more details on naming conventions.

        Specified by:
        getSimpleName in interface JElement
      • getProxy

        java.lang.Object getProxy()

        If a typed annotation proxy has been registered for the annotation represented by this JAnnotation, returns this object. Note that it's usually easier to access proxies by simply calling JAnnotatedElement.getAnnotationProxy(proxyClass).

        The value returned is guaranteed to be either a user-defined subclass of TypedAnnotationProxyBase or null.

      • getValues

        JAnnotationValue[] getValues()

        Returns an array of this annotation's member values.

      • getValue

        JAnnotationValue getValue​(java.lang.String named)

        Returns a structure which provides untyped, "by-name" access to the value of the named annotation member.

      • getAnnotationInstance

        java.lang.Object getAnnotationInstance()

        If this JAnnotation corresponds to metadata that is stored in a JSR175 annotation (i.e. an instance of java.lang.annotation.Annotation), returns that annotation object. Returns null if the annotation does not exist or is otherwise unavailable.

        Note that this is done only on a best-effort basis - the annotation object not be availble under pre-1.5 JREs and will generally only be available if the underlying annotation was view from a class file. Note that the retention policy of the annotation type usually must also be RUNTIME. Unless you are sure of all of these things, you are better off using an AnnotationProxy or the untyped value accessors (e.g. getValues()).

        If this method does return something other than null, it is guaranteed to be an instance of java.lang.annotation.Annotation. It is typed here as Object simply to preserve API compatibility with Java 1.4.