APIdia Launch Partner
Top Description Methods
javax.lang.model.element

public Interface VariableElement

extends Element
Imports
javax.lang.model.util.Elements, javax.lang.model.type.TypeMirror, .TypeKind

Represents a field, enum constant, method or constructor parameter, local variable, resource variable, or exception parameter.
Since
1.6
Java Language Specification
8.3 Field Declaration, 8.9.1 Enum Constants, 8.4.1 Formal Parameters, 8.8.1 Formal Parameters, 14.4 Local Variable Declarations, 14.20 The try statement, 14.20.3 try-with-resources

Method Summary

Modifier and TypeMethod and Description
public TypeMirror

Returns:

the type of this variable
asType
()

Redeclares javax.lang.model.element.Element.asType.

Returns the type of this variable.

public Object

Returns:

the value of this variable if this is a final field initialized to a compile-time constant, or null otherwise
getConstantValue
()

Returns the value of this variable if this is a final field initialized to a compile-time constant.

public Element

Returns:

the enclosing element of this variable
getEnclosingElement
()

Redeclares javax.lang.model.element.Element.getEnclosingElement.

Returns the enclosing element of this variable.

public Name

Returns:

the simple name of this variable element
getSimpleName
()

Redeclares javax.lang.model.element.Element.getSimpleName.

Returns the simple name of this variable element.

public default boolean

Returns:

true if this is an unnamed variable and false otherwise
isUnnamed
()

Returns true if this is an unnamed variable and false otherwise.

Inherited from javax.lang.model.element.Element:
acceptequalsgetAnnotationgetAnnotationMirrorsgetAnnotationsByTypegetEnclosedElementsgetKindgetModifiershashCode

Method Detail

asTypeback to summary
public TypeMirror asType()

Redeclares javax.lang.model.element.Element.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.

Returns:TypeMirror

the type of this variable

Annotations
@Override
See Also
TypeKind
getConstantValueback to summary
public Object getConstantValue()

Returns the value of this variable if this is a final field initialized to a compile-time constant. Returns null otherwise. The value will be of a primitive type or a String. If the value is of a primitive type, it is wrapped in the appropriate wrapper class (such as Integer).

Note that not all final fields will have constant values. In particular, enum constants are not considered to be compile-time constants. To have a constant value, a field's type must be either a primitive type or String.

Returns:Object

the value of this variable if this is a final field initialized to a compile-time constant, or null otherwise

Java Language Specification
15.29 Constant Expressions, 4.12.4 final Variables
See Also
Elements#getConstantExpression(Object)
getEnclosingElementback to summary
public Element getEnclosingElement()

Redeclares javax.lang.model.element.Element.getEnclosingElement.

Returns the enclosing element of this variable. The enclosing element of a method or constructor parameter is the executable declaring the parameter.

Returns:Element

the enclosing element of this variable

Annotations
@Override
getSimpleNameback to summary
public Name getSimpleName()

Redeclares javax.lang.model.element.Element.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.

Returns:Name

the simple name of this variable element

Annotations
@Override
isUnnamedback to summary
public default boolean isUnnamed()

Returns true if this is an unnamed variable and false otherwise.

Implementation Specification

The default implementation of this method calls getSimpleName() and returns true if the result is empty and false otherwise.

Returns:boolean

true if this is an unnamed variable and false otherwise

Since
22
Java Language Specification
6.1 Declarations, 14.4 Local Variable Declarations