public interface AnnotationMember
String
constants;Enum
constants;Class
literals;Annotation
s;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
.
Modifier and Type | Interface and Description |
---|---|
static class |
AnnotationMember.Kind
The kind of the annotation member value.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VALUE
Name of the commonly used
value() annotation member. |
Modifier and Type | Method and Description |
---|---|
java.util.List<AnnotationMember> |
asArray()
Returns this array value as an immutable
List of AnnotationMember s. |
boolean |
asBoolean()
Returns this value as a
boolean . |
byte |
asByte()
Returns this value as a
byte . |
char |
asChar()
Returns this value as a
char . |
double |
asDouble()
Returns this value as a
double . |
<E extends java.lang.Enum<E>> |
asEnum(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 a
float . |
int |
asInt()
Returns this value as an
int . |
long |
asLong()
Returns this value as a
long . |
AnnotationInfo |
asNestedAnnotation()
Returns this nested annotation value as an
AnnotationInfo . |
short |
asShort()
Returns this value as a
short . |
java.lang.String |
asString()
Returns this value as a
String . |
Type |
asType()
Returns this class value as a
Type . |
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.
|
static final java.lang.String VALUE
value()
annotation member.AnnotationMember.Kind kind()
null
default boolean isBoolean()
true
if the kind is a boolean
, false
otherwisedefault boolean isByte()
true
if the kind is a byte
, false
otherwisedefault boolean isShort()
true
if the kind is a short
, false
otherwisedefault boolean isInt()
true
if the kind is an int
, false
otherwisedefault boolean isLong()
true
if the kind is a long
, false
otherwisedefault boolean isFloat()
true
if the kind is a float
, false
otherwisedefault boolean isDouble()
true
if the kind is a double
, false
otherwisedefault boolean isChar()
true
if the kind is a char
, false
otherwisedefault boolean isString()
true
if the kind is a String
, false
otherwisedefault boolean isEnum()
true
if the kind is an Enum
, false
otherwisedefault boolean isClass()
true
if the kind is a Class
, false
otherwisedefault boolean isNestedAnnotation()
true
if the kind is a nested Annotation
, false
otherwisedefault boolean isArray()
true
if the kind is an array, false
otherwiseboolean asBoolean()
boolean
.java.lang.IllegalStateException
- if this annotation member value is not a boolean
byte asByte()
byte
.java.lang.IllegalStateException
- if this annotation member value is not a byte
short asShort()
short
.java.lang.IllegalStateException
- if this annotation member value is not a short
int asInt()
int
.java.lang.IllegalStateException
- if this annotation member value is not an int
long asLong()
long
.java.lang.IllegalStateException
- if this annotation member value is not a long
float asFloat()
float
.java.lang.IllegalStateException
- if this annotation member value is not a float
double asDouble()
double
.java.lang.IllegalStateException
- if this annotation member value is not a double
char asChar()
char
.java.lang.IllegalStateException
- if this annotation member value is not a char
java.lang.String asString()
String
.java.lang.IllegalStateException
- if this annotation member value is not a String
<E extends java.lang.Enum<E>> E asEnum(java.lang.Class<E> enumType)
E
- the enum generic typeenumType
- the enum typejava.lang.IllegalArgumentException
- if given enumType
is not an enum typejava.lang.IllegalStateException
- if this annotation member value is not an enum valueClassInfo asEnumClass()
ClassInfo
representing the enum typejava.lang.IllegalStateException
- if this annotation member value is not an enum valuejava.lang.String asEnumConstant()
java.lang.IllegalStateException
- if this annotation member value is not an enum valueType asType()
Type
. It can be:
Type
java.lang.IllegalStateException
- if this annotation member value is not a class valueAnnotationInfo asNestedAnnotation()
AnnotationInfo
.AnnotationInfo
instancejava.lang.IllegalStateException
- if this annotation member value is not a nested annotationjava.util.List<AnnotationMember> asArray()
List
of AnnotationMember
s.
Returns an empty list if the array is empty.AnnotationMember
sjava.lang.IllegalStateException
- if this annotation member value is not an array