Interface AnnotationMember


  • public interface AnnotationMember
    The value of an annotation member. Annotation member values are of several kinds:
    • primitive constants;
    • String constants;
    • Enum constants;
    • Class literals;
    • nested Annotations;
    • arrays of previously mentioned types.
    The kind() method returns the kind of this annotation member value. The is* methods (such as isBoolean()) allow checking if this annotation member value is of given kind. The as* methods (such as asBoolean()) allow "unwrapping" this annotation member value, if it is of the corresponding kind.

    Note that the as* methods do not perform type conversion, so if this annotation member value is an int, calling asLong() will throw an exception.

    Implementations of this interface are required to define the equals and hashCode methods. Implementations of this interface are encouraged to define the toString method such that it returns a text resembling the corresponding Java™ syntax.

    There is no guarantee that any particular annotation member, represented by an implementation of this interface, will always be represented by the same object. This includes natural singletons such as boolean values. Instances should always be compared using equals.

    Since:
    4.0
    • Method Detail

      • kind

        AnnotationMember.Kind kind()
        Returns the kind of this annotation member value.
        Returns:
        the kind of this annotation member value, never null
      • isBoolean

        default boolean isBoolean()
        Returns:
        true if the kind is a boolean, false otherwise
      • isByte

        default boolean isByte()
        Returns:
        true if the kind is a byte, false otherwise
      • isShort

        default boolean isShort()
        Returns:
        true if the kind is a short, false otherwise
      • isInt

        default boolean isInt()
        Returns:
        true if the kind is an int, false otherwise
      • isLong

        default boolean isLong()
        Returns:
        true if the kind is a long, false otherwise
      • isFloat

        default boolean isFloat()
        Returns:
        true if the kind is a float, false otherwise
      • isDouble

        default boolean isDouble()
        Returns:
        true if the kind is a double, false otherwise
      • isChar

        default boolean isChar()
        Returns:
        true if the kind is a char, false otherwise
      • isString

        default boolean isString()
        Returns:
        true if the kind is a String, false otherwise
      • isEnum

        default boolean isEnum()
        Returns:
        true if the kind is an Enum, false otherwise
      • isClass

        default boolean isClass()
        Returns:
        true if the kind is a Class, false otherwise
      • isNestedAnnotation

        default boolean isNestedAnnotation()
        Returns:
        true if the kind is a nested Annotation, false otherwise
      • isArray

        default boolean isArray()
        Returns:
        true if the kind is an array, false otherwise
      • asBoolean

        boolean asBoolean()
        Returns this value as a boolean.
        Returns:
        the boolean value
        Throws:
        IllegalStateException - if this annotation member value is not a boolean
      • asByte

        byte asByte()
        Returns this value as a byte.
        Returns:
        the byte value
        Throws:
        IllegalStateException - if this annotation member value is not a byte
      • asShort

        short asShort()
        Returns this value as a short.
        Returns:
        the short value
        Throws:
        IllegalStateException - if this annotation member value is not a short
      • asInt

        int asInt()
        Returns this value as an int.
        Returns:
        the int value
        Throws:
        IllegalStateException - if this annotation member value is not an int
      • asLong

        long asLong()
        Returns this value as a long.
        Returns:
        the long value
        Throws:
        IllegalStateException - if this annotation member value is not a long
      • asFloat

        float asFloat()
        Returns this value as a float.
        Returns:
        the float value
        Throws:
        IllegalStateException - if this annotation member value is not a float
      • asDouble

        double asDouble()
        Returns this value as a double.
        Returns:
        the double value
        Throws:
        IllegalStateException - if this annotation member value is not a double
      • asChar

        char asChar()
        Returns this value as a char.
        Returns:
        the char value
        Throws:
        IllegalStateException - if this annotation member value is not a char
      • asString

        String asString()
        Returns this value as a String.
        Returns:
        the String value
        Throws:
        IllegalStateException - if this annotation member value is not a String
      • asEnum

        <E extends Enum<E>> E asEnum​(Class<E> enumType)
        Returns this enum value as an instance of the enum type.
        Type Parameters:
        E - the enum generic type
        Parameters:
        enumType - the enum type
        Returns:
        the enum instance
        Throws:
        IllegalArgumentException - if given enumType is not an enum type
        IllegalStateException - if this annotation member value is not an enum value
      • asEnumClass

        ClassInfo asEnumClass()
        Returns the type of this enum value.
        Returns:
        a ClassInfo representing the enum type
        Throws:
        IllegalStateException - if this annotation member value is not an enum value
      • asEnumConstant

        String asEnumConstant()
        Returns the name of this enum value.
        Returns:
        the name of this enum value
        Throws:
        IllegalStateException - if this annotation member value is not an enum value
      • asType

        Type asType()
        Returns this class value as a Type. It can be:
        • the void pseudo-type;
        • a primitive type;
        • a class type;
        • an array type, whose element type is a primitive type or a class type.
        Returns:
        the class value, as a Type
        Throws:
        IllegalStateException - if this annotation member value is not a class value