Java Reference
In-Depth Information
Each dimension expression undergoes unary numeric promotion (§ 5.6.1 ) . The promoted
type must be int , or a compile-time error occurs.
The type of the array creation expression is an array type that can denoted by a copy of the
array creation expression from which the new keyword and every DimExpr expression and
array initializer have been deleted.
For example, the type of the creation expression:
new double[3][3][]
is:
double[][][]
15.10.1. Run-Time Evaluation of Array Creation Expressions
At run time, evaluation of an array creation expression behaves as follows:
• If there are no dimension expressions, then there must be an array initializer.
A newly allocated array will be initialized with the values provided by the array
initializer as described in § 10.6 .
The value of the array initializer becomes the value of the array creation expres-
sion.
• Otherwise, there is no array initializer, and:
♦ First, the dimension expressions are evaluated, left-to-right. If any of the ex-
pression evaluations completes abruptly, the expressions to the right of it are
not evaluated.
♦ Next, the values of the dimension expressions are checked. If the value of any
DimExpr expression is less than zero, then a NegativeArraySizeException is
thrown.
♦ Next, space is allocated for the new array. If there is insufficient space to alloc-
ate the array, evaluation of the array creation expression completes abruptly by
throwing an OutOfMemoryError .
♦ Then, if a single DimExpr appears, a one-dimensional array is created of the
specified length, and each component of the array is initialized to its default
value (§ 4.12.5 ) .
♦ Otherwise, if n DimExpr expressions appear, then array creation effectively ex-
ecutes a set of nested loops of depth n -1 to create the implied arrays of arrays.
A multidimensional array need not have arrays of the same length at each level.
Search WWH ::




Custom Search