Java Reference
In-Depth Information
pression completes abruptly for the same reason and the right-hand operand is not
evaluated and no assignment occurs.
• Otherwise, the right-hand operand is evaluated. If this evaluation completes ab-
ruptly, then the assignment expression completes abruptly for the same reason and
no assignment occurs.
• Otherwise, if the value of the array reference subexpression is
null
, then no assign-
ment occurs and a
NullPointerException
is thrown.
• Otherwise, the value of the array reference subexpression indeed refers to an array.
If the value of the index subexpression is less than zero, or greater than or equal to
the
length
of the array, then no assignment occurs and an
ArrayIndexOutOfBoundsEx-
ception
is thrown.
• Otherwise, the value of the index subexpression is used to select a component of
the array referred to by the value of the array reference subexpression.
This component is a variable; call its type
SC
. Also, let
TC
be the type of the left-
hand operand of the assignment operator as determined at compile time. Then
there are two possibilities:
♦ If
TC
is a primitive type, then
SC
is necessarily the same as
TC
.
The value of the right-hand operand is converted to the type of the selected ar-
standard value set (not an extended-exponent value set), and the result of the
conversion is stored into the array component.
♦ If
TC
is a reference type, then
SC
may not be the same as
TC
, but rather a type
that extends or implements
TC
.
Let
RC
be the class of the object referred to by the value of the right-hand oper-
and at run time.
A Java compiler may be able to prove at compile time that the array component
will be of type
TC
exactly (for example,
TC
might be
final
). But if a Java com-
piler cannot prove at compile time that the array component will be of type
TC
exactly, then a check must be performed at run time to ensure that the class
RC
ent.
check fails, an
ArrayStoreException
is thrown rather than a
ClassCastException
.
If class
RC
is not assignable to type
SC
, then no assignment occurs and an
Ar-
rayStoreException
is thrown.