3 ms·
The Java code ends up being different in subtle ways. Exemplified by this: static int x[] = new int[1]; public static void main1(String[] args) { x[1]
by logn 12y ago
The Java code ends up being different in subtle ways. Exemplified by this:
static int x[] = new int[1];
public static void main1(String[] args) {
x[1] = grow() ? 10 : 20; //array index out of bounds!
}
public static void main2(String[] args) {
if (grow()) {
x[1] = 10;
} else {
x[1] = 20;
}
//no exceptions thrown
}
private static boolean grow() {
x = new int[2];
return true;
}