There are 12 assignment operators; all are syntactically right-associative (they
group right-to-left). Thus, a=b=c
means a=(b=c)
, which assigns the value of c
to
b
and then assigns the value of b
to a
.
AssignmentExpression:
ConditionalExpression
Assignment Assignment:
LeftHandSideAssignmentOperator
AssignmentExpression LeftHandSide:
ExpressionName
FieldAccess
ArrayAccess AssignmentOperator: one of
= *= /= %= += -= <<= >>= >>>= &= ^= |=
The result of the first operand of an assignment operator must be a variable, or a compile-time error occurs. This operand may be a named variable, such as a local variable or a field of the current object or class, or it may be a computed variable, as can result from a field access (§15.10) or an array access (§15.12). The type of the assignment expression is the type of the variable.
At run time, the result of the assignment expression is the value of the variable after the assignment has occurred. The result of an assignment expression is not itself a variable.
A variable that is declared final
cannot be assigned to, because when an access of a final
variable is used as an expression, the result is a value, not a variable, and so it cannot be used as the operand of an assignment operator.