15.12.1 Run-time Evaluation
An array access expression is evaluated using the following procedure:
- First, the array reference expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason and the index expression is not evaluated.
- Otherwise, the index expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason.
- Otherwise, if the value of the array reference expression is
null
, then a NullPointerException
is thrown.
- Otherwise, the value of the array reference expression indeed refers to an array. If the value of the index expression is less than zero, or greater than or equal to the array's length, then an
IndexOutOfBoundsException
is thrown.
- Otherwise, the result of the array reference is the variable of type T, within the array, selected by the value of the index expression. (Note that this resulting variable, which is a component of the array, is never considered
final
, even if the array reference expression is a final
variable.)