Java Reference
In-Depth Information
The type of the assignment expression is the type of the variable after capture conversion
5.1.10 ) .
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 (unless it is definitely unassigned
(§16)), because when an access of such a final variable is used as an expression, the result
is a value, not a variable, and so it cannot be used as the first operand of an assignment
operator.
15.26.1. Simple Assignment Operator =
A compile-time error occurs if the type of the right-hand operand cannot be converted to
the type of the variable by assignment conversion (§ 5.2 ) .
At run time, the expression is evaluated in one of three ways.
If the left-hand operand expression is a field access expression (§ 15.11 ) e.f , possibly en-
closed in one or more pairs of parentheses, then:
• First, the expression e is evaluated. If evaluation of e completes abruptly, the as-
signment expression completes abruptly for the same reason.
• Next, the right hand operand is evaluated. If evaluation of the right hand expres-
sion completes abruptly, the assignment expression completes abruptly for the
same reason.
• Then, if the field denoted by e.f is not static and the result of the evaluation of e
above is null , then a NullPointerException is thrown.
• Otherwise, the variable denoted by e.f is assigned the value of the right hand oper-
and as computed above.
If the left-hand operand is an array access expression (§ 15.13 ), possibly enclosed in one or
more pairs of parentheses, then:
• First, the array reference subexpression of the left-hand operand array access ex-
pression is evaluated. If this evaluation completes abruptly, then the assignment
expression completes abruptly for the same reason; the index subexpression (of the
left-hand operand array access expression) and the right-hand operand are not
evaluated and no assignment occurs.
• Otherwise, the index subexpression of the left-hand operand array access expres-
sion is evaluated. If this evaluation completes abruptly, then the assignment ex-
Search WWH ::




Custom Search