Interface VariableElement
- All Superinterfaces:
AnnotatedConstruct,Element
Represents a field,
enum constant, method or constructor
parameter, local variable, resource variable, or exception
parameter.- Since:
- 1.6
-
Method Summary
Modifier and TypeMethodDescriptionasType()Returns the type of this variable.Returns the value of this variable if this is afinalfield initialized to a compile-time constant.Returns the enclosing element of this variable.Returns the simple name of this variable element.default booleanReturnstrueif this is an unnamed variable andfalseotherwise.Methods declared in interface javax.lang.model.element.Element
accept, equals, getAnnotation, getAnnotationMirrors, getAnnotationsByType, getEnclosedElements, getKind, getModifiers, hashCode
-
Method Details
-
asType
TypeMirror asType()Returns the type of this variable. Note that the types of variables range over many kinds of types, including primitive types, declared types, and array types, among others. -
getConstantValue
Object getConstantValue()Returns the value of this variable if this is afinalfield initialized to a compile-time constant. Returnsnullotherwise. The value will be of a primitive type or aString. If the value is of a primitive type, it is wrapped in the appropriate wrapper class (such asInteger).Note that not all
finalfields will have constant values. In particular,enumconstants are not considered to be compile-time constants. To have a constant value, a field's type must be either a primitive type orString.- Returns:
- the value of this variable if this is a
finalfield initialized to a compile-time constant, ornullotherwise - See Java Language Specification:
-
15.29 Constant Expressions
4.12.4 final Variables - See Also:
-
getSimpleName
Name getSimpleName()Returns the simple name of this variable element.For method and constructor parameters, the name of each parameter must be distinct from the names of all other parameters of the same executable. If the original source names are not available, an implementation may synthesize names subject to the distinctness requirement above.
For variables, the name of each variable is returned, or an empty name if the variable is unnamed.
- Specified by:
getSimpleNamein interfaceElement- Returns:
- the simple name of this variable element
- See Also:
-
getEnclosingElement
Element getEnclosingElement()Returns the enclosing element of this variable. The enclosing element of a method or constructor parameter is the executable declaring the parameter.- Specified by:
getEnclosingElementin interfaceElement- Returns:
- the enclosing element of this variable
- See Also:
-
isUnnamed
default boolean isUnnamed()Returnstrueif this is an unnamed variable andfalseotherwise.- Implementation Requirements:
- The default implementation of this method calls
getSimpleName()and returnstrueif the result is empty andfalseotherwise. - Returns:
trueif this is an unnamed variable andfalseotherwise- See Java Language Specification:
-
6.1 Declarations
14.4 Local Variable Declarations - Since:
- 22
-