Java Reference
In-Depth Information
A variable that is declared
final
cannot be incremented because when an access of such a
final
variable is used as an expression, the result is a value, not a variable. Thus, it cannot
be used as the operand of a prefix increment operator.
15.15.2. Prefix Decrement Operator
--
A unary expression preceded by a
--
operator is a prefix decrement expression.
to a numeric type, or a compile-time error occurs.
The type of the prefix decrement expression is the type of the variable. The result of the
prefix decrement expression is not a variable, but a value.
At run time, if evaluation of the operand expression completes abruptly, then the prefix
decrement expression completes abruptly for the same reason and no decrementation oc-
curs. Otherwise, the value
1
is subtracted from the value of the variable and the difference
is performed on the value
1
and the value of the variable. If necessary, the difference is nar-
expression is the value of the variable
after
the new value is stored.
Note that the binary numeric promotion mentioned above may include unboxing con-
applied to the difference prior to its being stored in the variable.
A variable that is declared
final
cannot be decremented because when an access of such a
final
variable is used as an expression, the result is a value, not a variable. Thus, it cannot
be used as the operand of a prefix decrement operator.
15.15.3. Unary Plus Operator
+
The type of the operand expression of the unary
+
operator must be a type that is convertible
expression is the promoted type of the operand. The result of the unary plus expression is
not a variable, but a value, even if the result of the operand expression is a variable.
At run time, the value of the unary plus expression is the promoted value of the operand.