-
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. Theis*
methods (such asisBoolean()
) allow checking if this annotation member value is of given kind. Theas*
methods (such asasBoolean()
) 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 anint
, callingasLong()
will throw an exception.Implementations of this interface are required to define the
equals
andhashCode
methods. Implementations of this interface are encouraged to define thetoString
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 usingequals
.- Since:
- 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
AnnotationMember.Kind
The kind of the annotation member value.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
VALUE
Name of the commonly usedvalue()
annotation member.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.List<AnnotationMember>
asArray()
Returns this array value as an immutableList
ofAnnotationMember
s.boolean
asBoolean()
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 java.lang.Enum<E>>
EasEnum(java.lang.Class<E> enumType)
Returns this enum value as an instance of the enum type.ClassInfo
asEnumClass()
Returns the type of this enum value.java.lang.String
asEnumConstant()
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
.AnnotationInfo
asNestedAnnotation()
Returns this nested annotation value as anAnnotationInfo
.short
asShort()
Returns this value as ashort
.java.lang.String
asString()
Returns this value as aString
.Type
asType()
Returns this class value as aType
.default boolean
isArray()
default boolean
isBoolean()
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
isNestedAnnotation()
default boolean
isShort()
default boolean
isString()
AnnotationMember.Kind
kind()
Returns the kind of this annotation member value.
-
-
-
Field Detail
-
VALUE
static final java.lang.String VALUE
Name of the commonly usedvalue()
annotation member.- See Also:
- Constant Field Values
-
-
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 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:
java.lang.IllegalStateException
- if this annotation member value is not aboolean
-
asByte
byte asByte()
Returns this value as abyte
.- Returns:
- the byte value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not abyte
-
asShort
short asShort()
Returns this value as ashort
.- Returns:
- the short value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not ashort
-
asInt
int asInt()
Returns this value as anint
.- Returns:
- the int value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not anint
-
asLong
long asLong()
Returns this value as along
.- Returns:
- the long value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not along
-
asFloat
float asFloat()
Returns this value as afloat
.- Returns:
- the float value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not afloat
-
asDouble
double asDouble()
Returns this value as adouble
.- Returns:
- the double value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not adouble
-
asChar
char asChar()
Returns this value as achar
.- Returns:
- the char value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not achar
-
asString
java.lang.String asString()
Returns this value as aString
.- Returns:
- the String value
- Throws:
java.lang.IllegalStateException
- if this annotation member value is not aString
-
asEnum
<E extends java.lang.Enum<E>> E asEnum(java.lang.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:
java.lang.IllegalArgumentException
- if givenenumType
is not an enum typejava.lang.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:
java.lang.IllegalStateException
- if this annotation member value is not an enum value
-
asEnumConstant
java.lang.String asEnumConstant()
Returns the name of this enum value.- Returns:
- the name of this enum value
- Throws:
java.lang.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:
java.lang.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:
java.lang.IllegalStateException
- if this annotation member value is not a nested annotation
-
asArray
java.util.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:
java.lang.IllegalStateException
- if this annotation member value is not an array
-
-