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
  • Field Details Link icon

  • Method Details Link icon

    • kind Link icon

      Returns the kind of this annotation member value.
      Returns:
      the kind of this annotation member value, never null
    • isBoolean Link icon

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      <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 Link icon

      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 Link icon

      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 Link icon

      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
    • asNestedAnnotation Link icon

      AnnotationInfo asNestedAnnotation()
      Returns this nested annotation value as an AnnotationInfo.
      Returns:
      an AnnotationInfo instance
      Throws:
      IllegalStateException - if this annotation member value is not a nested annotation
    • asArray Link icon

      Returns this array value as an immutable List of AnnotationMembers. Returns an empty list if the array is empty.
      Returns:
      an immutable list of AnnotationMembers
      Throws:
      IllegalStateException - if this annotation member value is not an array