Package jakarta.enterprise.lang.model
Interface AnnotationMember
public interface AnnotationMember
The value of an annotation member. Annotation member values are of several kinds:
- primitive constants;
Stringconstants;Enumconstants;Classliterals;- nested
Annotations; - 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
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe kind of the annotation member value. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasArray()Returns this array value as an immutableListofAnnotationMembers.booleanReturns this value as aboolean.byteasByte()Returns this value as abyte.charasChar()Returns this value as achar.doubleasDouble()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.floatasFloat()Returns this value as afloat.intasInt()Returns this value as anint.longasLong()Returns this value as along.Returns this nested annotation value as anAnnotationInfo.shortasShort()Returns this value as ashort.asString()Returns this value as aString.asType()Returns this class value as aType.default booleanisArray()default booleandefault booleanisByte()default booleanisChar()default booleanisClass()default booleanisDouble()default booleanisEnum()default booleanisFloat()default booleanisInt()default booleanisLong()default booleandefault booleanisShort()default booleanisString()kind()Returns the kind of this annotation member value.
-
Field Details
-
VALUE
Name of the commonly usedvalue()annotation member.- See Also:
-
-
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:
trueif the kind is aboolean,falseotherwise
-
isByte
default boolean isByte()- Returns:
trueif the kind is abyte,falseotherwise
-
isShort
default boolean isShort()- Returns:
trueif the kind is ashort,falseotherwise
-
isInt
default boolean isInt()- Returns:
trueif the kind is anint,falseotherwise
-
isLong
default boolean isLong()- Returns:
trueif the kind is along,falseotherwise
-
isFloat
default boolean isFloat()- Returns:
trueif the kind is afloat,falseotherwise
-
isDouble
default boolean isDouble()- Returns:
trueif the kind is adouble,falseotherwise
-
isChar
default boolean isChar()- Returns:
trueif the kind is achar,falseotherwise
-
isString
default boolean isString()- Returns:
trueif the kind is aString,falseotherwise
-
isEnum
default boolean isEnum()- Returns:
trueif the kind is anEnum,falseotherwise
-
isClass
default boolean isClass()- Returns:
trueif the kind is aClass,falseotherwise
-
isNestedAnnotation
default boolean isNestedAnnotation()- Returns:
trueif the kind is a nestedAnnotation,falseotherwise
-
isArray
default boolean isArray()- Returns:
trueif the kind is an array,falseotherwise
-
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 givenenumTypeis 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
ClassInforepresenting 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
AnnotationInfoinstance - Throws:
IllegalStateException- if this annotation member value is not a nested annotation
-
asArray
List<AnnotationMember> asArray()Returns this array value as an immutableListofAnnotationMembers. 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
-