Resolves and returns the compile-time constant expression value as specified in JLS2 15.28, if this expression has one. Constant expression values are unavailable unless bindings are requested when the AST is being built. If the type of the value is a primitive type, the result is the boxed equivalent (i.e., int returned as an
Integer
); if the type of the value is
String
, the result is the string itself. If the expression does not have a compile-time constant expression value, the result is
null
.
Resolving constant expressions takes into account the value of simple and qualified names that refer to constant variables (JLS2 4.12.4).
Note 1: enum constants are not considered constant expressions. The result is always null
for these.
Note 2: Compile-time constant expressions cannot denote null
. So technically {@link NullLiteral} nodes are not constant expressions.The result is null
for these nonetheless.
@return the constant expression value, or
null
if thisexpression has no constant expression value or if bindings were not requested when the AST was created
@since 3.1