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
Annotation
s; - arrays of previously mentioned types.
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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
The kind of the annotation member value. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionasArray()
Returns this array value as an immutableList
ofAnnotationMember
s.boolean
Returns this value as aboolean
.byte
asByte()
Returns this value as abyte
.char
asChar()
Returns this value as achar
.double
asDouble()
Returns this value as adouble
.<E extends Enum<E>>
EReturns this enum value as an instance of the enum type.Returns the type of this enum value.Returns the name of this enum value.float
asFloat()
Returns this value as afloat
.int
asInt()
Returns this value as anint
.long
asLong()
Returns this value as along
.Returns this nested annotation value as anAnnotationInfo
.short
asShort()
Returns this value as ashort
.asString()
Returns this value as aString
.asType()
Returns this class value as aType
.default boolean
isArray()
default boolean
default boolean
isByte()
default boolean
isChar()
default boolean
isClass()
default boolean
isDouble()
default boolean
isEnum()
default boolean
isFloat()
default boolean
isInt()
default boolean
isLong()
default boolean
default boolean
isShort()
default boolean
isString()
kind()
Returns the kind of this annotation member value.
-
Field Details
-
VALUE
-
-
Method Details
-
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 aboolean
,false
otherwise
-
isByte
default boolean isByte()- Returns:
true
if the kind is abyte
,false
otherwise
-
isShort
default boolean isShort()- Returns:
true
if the kind is ashort
,false
otherwise
-
isInt
default boolean isInt()- Returns:
true
if the kind is anint
,false
otherwise
-
isLong
default boolean isLong()- Returns:
true
if the kind is along
,false
otherwise
-
isFloat
default boolean isFloat()- Returns:
true
if the kind is afloat
,false
otherwise
-
isDouble
default boolean isDouble()- Returns:
true
if the kind is adouble
,false
otherwise
-
isChar
default boolean isChar()- Returns:
true
if the kind is achar
,false
otherwise
-
isString
default boolean isString()- Returns:
true
if the kind is aString
,false
otherwise
-
isEnum
default boolean isEnum()- Returns:
true
if the kind is anEnum
,false
otherwise
-
isClass
default boolean isClass()- Returns:
true
if the kind is aClass
,false
otherwise
-
isNestedAnnotation
default boolean isNestedAnnotation()- Returns:
true
if the kind is a nestedAnnotation
,false
otherwise
-
isArray
default boolean isArray()- Returns:
true
if the kind is an array,false
otherwise
-
asBoolean
boolean asBoolean()Returns this value as aboolean
.- Returns:
- the boolean value
- Throws:
IllegalStateException
- if this annotation member value is not aboolean
-
asByte
byte asByte()Returns this value as abyte
.- Returns:
- the byte value
- Throws:
IllegalStateException
- if this annotation member value is not abyte
-
asShort
short asShort()Returns this value as ashort
.- Returns:
- the short value
- Throws:
IllegalStateException
- if this annotation member value is not ashort
-
asInt
int asInt()Returns this value as anint
.- Returns:
- the int value
- Throws:
IllegalStateException
- if this annotation member value is not anint
-
asLong
long asLong()Returns this value as along
.- Returns:
- the long value
- Throws:
IllegalStateException
- if this annotation member value is not along
-
asFloat
float asFloat()Returns this value as afloat
.- Returns:
- the float value
- Throws:
IllegalStateException
- if this annotation member value is not afloat
-
asDouble
double asDouble()Returns this value as adouble
.- Returns:
- the double value
- Throws:
IllegalStateException
- if this annotation member value is not adouble
-
asChar
char asChar()Returns this value as achar
.- Returns:
- the char value
- Throws:
IllegalStateException
- if this annotation member value is not achar
-
asString
String asString()Returns this value as aString
.- Returns:
- the String value
- Throws:
IllegalStateException
- if this annotation member value is not aString
-
asEnum
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 givenenumType
is not an enum typeIllegalStateException
- 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 aType
. It can be:- Returns:
- the class value, as a
Type
- Throws:
IllegalStateException
- if this annotation member value is not a class value
-
asNestedAnnotation
AnnotationInfo asNestedAnnotation()Returns this nested annotation value as anAnnotationInfo
.- Returns:
- an
AnnotationInfo
instance - Throws:
IllegalStateException
- if this annotation member value is not a nested annotation
-
asArray
List<AnnotationMember> asArray()Returns this array value as an immutableList
ofAnnotationMember
s. Returns an empty list if the array is empty.- Returns:
- an immutable list of
AnnotationMember
s - Throws:
IllegalStateException
- if this annotation member value is not an array
-