Java Reference
In-Depth Information
Here the next value is read from a stream and stored in the variable
v
.
Provided the value read was not
null
, it is processed and the next value
read. Note that as assignment has a lower precedence than the inequal-
ity test (see "
Operator Precedence and Associativity
"
on page
221
)
, you
have to place the assignment expression within parentheses.
The simple
=
is the most basic form of assignment operator. There are
many other assignment forms. Any binary arithmetic, logical, or bit ma-
nipulation operator can be concatenated with
=
to form another assign-
ment operatora
compound assignment operator.
For example,
arr[where()] += 12;
is the same as
arr[where()] = arr[where()] + 12;
except that the expression on the left-hand side of the assignment is
evaluated only once. In the example,
arr[where()]
is evaluated only once
in the first expression, but twice in the second expressionas you learned
earlier with the
++
operator.
Given the variable
var
of type
T
, the value
expr
, and the binary operator
op
, the expression
var
op
= expr
is equivalent to
var = (T) ((var)
op
(expr))