各位大侠能否请教我以下几点:
片段1:
public class ArrayKoPo {
public static int[] getArray() {
return null;
}
public static void main(String args[]) {
int i = 0;
try {
int j = getArray()[i++];
} catch (Exception e) {
System.out.println(i); //prints 1 <---- This one I expected.
}
}
}
片段 2:
public class ArrayKoPo {
public static int[][] getArray() {
return null;
}
public static void main(String args[]) {
int i = 0;
try {
int j = getArray()[i++][i++];
} catch (Exception e) {
System.out.println(i); //still prints 1 <---- This one I don't understand. I thought 2 will be printed.
}
}
}
为什么变量 i 在第二个代码块中没有增加两次?
我错过了什么?
谢谢。