Java Reference
In-Depth Information
PreIncrementExpression
PreDecrementExpression
+
UnaryExpression
-
UnaryExpression
UnaryExpressionNotPlusMinus
PreIncrementExpression:
++
UnaryExpression
PreDecrementExpression:
--
UnaryExpression
UnaryExpressionNotPlusMinus:
PostfixExpression
~
UnaryExpression
!
UnaryExpression
CastExpression
Expressions with unary operators group right-to-left, so that
-~x
means the same as
-(~x)
.
15.15.1. Prefix Increment Operator
++
A unary expression preceded by a
++
operator is a prefix increment expression.
to a numeric type, or a compile-time error occurs.
The type of the prefix increment expression is the type of the variable. The result of the
prefix increment expression is not a variable, but a value.
At run time, if evaluation of the operand expression completes abruptly, then the prefix in-
crement expression completes abruptly for the same reason and no incrementation occurs.
Otherwise, the value
1
is added to the value of the variable and the sum is stored back into
value
1
and the value of the variable. If necessary, the sum is narrowed by a narrowing
the variable before it is stored. The value of the prefix increment 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-
is applied to the sum prior to its being stored in the variable.