VariableElement (Java Platform SE 8 ) (original) (raw)
- All Superinterfaces:
AnnotatedConstruct, Element
public interface VariableElement
extends Element
Represents a field, enum
constant, method or constructor parameter, local variable, resource variable, or exception parameter.
Since:
1.6
Method Summary
All Methods Instance Methods Abstract Methods
Modifier and Type Method Description Object getConstantValue() Returns the value of this variable if this is a final field initialized to a compile-time constant. Element getEnclosingElement() Returns the enclosing element of this variable. Name getSimpleName() Returns the simple name of this variable element. * ### Methods inherited from interface javax.lang.model.element.[Element](../../../../javax/lang/model/element/Element.html "interface in javax.lang.model.element") `[accept](../../../../javax/lang/model/element/Element.html#accept-javax.lang.model.element.ElementVisitor-P-), [asType](../../../../javax/lang/model/element/Element.html#asType--), [equals](../../../../javax/lang/model/element/Element.html#equals-java.lang.Object-), [getAnnotation](../../../../javax/lang/model/element/Element.html#getAnnotation-java.lang.Class-), [getAnnotationMirrors](../../../../javax/lang/model/element/Element.html#getAnnotationMirrors--), [getEnclosedElements](../../../../javax/lang/model/element/Element.html#getEnclosedElements--), [getKind](../../../../javax/lang/model/element/Element.html#getKind--), [getModifiers](../../../../javax/lang/model/element/Element.html#getModifiers--), [hashCode](../../../../javax/lang/model/element/Element.html#hashCode--)` * ### Methods inherited from interface javax.lang.model.[AnnotatedConstruct](../../../../javax/lang/model/AnnotatedConstruct.html "interface in javax.lang.model") `[getAnnotationsByType](../../../../javax/lang/model/AnnotatedConstruct.html#getAnnotationsByType-java.lang.Class-)`
Method Detail
* #### getConstantValue [Object](../../../../java/lang/Object.html "class in java.lang") 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](../../../../java/lang/Integer.html "class in java.lang")). 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: the value of this variable if this is a `final` field initialized to a compile-time constant, or `null` otherwise See Also: [Elements.getConstantExpression(Object)](../../../../javax/lang/model/util/Elements.html#getConstantExpression-java.lang.Object-) See The Java™ Language Specification: 15.28 Constant Expression, 4.12.4 final Variables * #### getSimpleName [Name](../../../../javax/lang/model/element/Name.html "interface in javax.lang.model.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. Specified by: `[getSimpleName](../../../../javax/lang/model/element/Element.html#getSimpleName--)` in interface `[Element](../../../../javax/lang/model/element/Element.html "interface in javax.lang.model.element")` Returns: the simple name of this variable element See Also: [PackageElement.getSimpleName()](../../../../javax/lang/model/element/PackageElement.html#getSimpleName--), [ExecutableElement.getSimpleName()](../../../../javax/lang/model/element/ExecutableElement.html#getSimpleName--), [TypeElement.getSimpleName()](../../../../javax/lang/model/element/TypeElement.html#getSimpleName--), [getSimpleName()](../../../../javax/lang/model/element/VariableElement.html#getSimpleName--) * #### getEnclosingElement [Element](../../../../javax/lang/model/element/Element.html "interface in javax.lang.model.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: `[getEnclosingElement](../../../../javax/lang/model/element/Element.html#getEnclosingElement--)` in interface `[Element](../../../../javax/lang/model/element/Element.html "interface in javax.lang.model.element")` Returns: the enclosing element of this variable See Also: [Elements.getPackageOf(javax.lang.model.element.Element)](../../../../javax/lang/model/util/Elements.html#getPackageOf-javax.lang.model.element.Element-)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.