Java Reference
In-Depth Information
subexpression, but for a compound assignment operator, the evaluation of the
right-hand operand occurs after these checks.
• Otherwise, consider the array component selected in the previous step, whose
value was saved. This component is a variable; call its type S . Also, let T be the
type of the left-hand operand of the assignment operator as determined at compile
time.
♦ If T is a primitive type, then S is necessarily the same as T .
The saved value of the array component and the value of the right-hand operand
are used to perform the binary operation indicated by the compound assignment
operator.
If this operation completes abruptly (the only possibility is an integer division
by zero - see § 15.17.2 ) , then the assignment expression completes abruptly for
the same reason and no assignment occurs.
Otherwise, the result of the binary operation is converted to the type of the se-
lected array component, subjected to value set conversion (§ 5.1.13 ) to the ap-
propriate standard value set (not an extended-exponent value set), and the result
of the conversion is stored into the array component.
♦ If T is a reference type, then it must be String . Because class String is a final
class, S must also be String .
Therefore the run-time check that is sometimes required for the simple assign-
ment operator is never required for a compound assignment operator.
The saved value of the array component and the value of the right-hand operand
are used to perform the binary operation (string concatenation) indicated by the
compound assignment operator (which is necessarily += ). If this operation com-
pletes abruptly, then the assignment expression completes abruptly for the same
reason and no assignment occurs.
Otherwise, the String result of the binary operation is stored into the array com-
ponent.
Example 15.26.2-1. Compound Assignment To An Array Component
Click here to view code image
class ArrayReferenceThrow extends RuntimeException { }
class IndexThrow extends RuntimeException { }
class RightHandSideThrow extends RuntimeException { }
class IllustrateCompoundArrayAssignment {
Search WWH ::




Custom Search