Java Reference
In-Depth Information
Example 15.10.1-1. Array Creation Evaluation
In an array creation expression with one or more dimension expressions, each dimen-
sion expression is fully evaluated before any part of any dimension expression to its
right. Thus:
Click here to view code image
class Test1 {
public static void main(String[] args) {
int i = 4;
int ia[][] = new int[i][i=3];
System.out.println(
"[" + ia.length + "," + ia[0].length + "]");
}
}
prints:
[4,3]
because the first dimension is calculated as 4 before the second dimension expression
sets i to 3 .
If evaluation of a dimension expression completes abruptly, no part of any dimension
expression to its right will appear to have been evaluated. Thus:
Click here to view code image
class Test2 {
public static void main(String[] args) {
int[][] a = { { 00, 01 }, { 10, 11 } };
int i = 99;
try {
a[val()][i = 1]++;
} catch (Exception e) {
System.out.println(e + ", i=" + i);
}
}
static int val() throws Exception {
throw new Exception("unimplemented");
}
}
prints:
java.lang.Exception: unimplemented, i=99
Search WWH ::




Custom Search