Package jakarta.enterprise.lang.model
Interface AnnotationMember
-
public interface AnnotationMemberThe 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. 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
equalsandhashCodemethods. Implementations of this interface are encouraged to define thetoStringmethod 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
booleanvalues. Instances should always be compared usingequals.- Since:
- 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAnnotationMember.KindThe kind of the annotation member value.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description List<AnnotationMember>asArray()Returns this array value as an immutableListofAnnotationMembers.booleanasBoolean()Returns 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>>
EasEnum(Class<E> enumType)Returns this enum value as an instance of the enum type.ClassInfoasEnumClass()Returns the type of this enum value.StringasEnumConstant()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.AnnotationInfoasNestedAnnotation()Returns this nested annotation value as anAnnotationInfo.shortasShort()Returns this value as ashort.StringasString()Returns this value as aString.TypeasType()Returns this class value as aType.default booleanisArray()default booleanisBoolean()default booleanisByte()default booleanisChar()default booleanisClass()default booleanisDouble()default booleanisEnum()default booleanisFloat()default booleanisInt()default booleanisLong()default booleanisNestedAnnotation()default booleanisShort()default booleanisString()AnnotationMember.Kindkind()Returns the kind of this annotation member value.
-
-
-
Field Detail
-
VALUE
static final 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:
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
<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 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
-
-