對此related question的答案表示一維數組是零引用的。從我剛跑過的一個小測試看來,似乎多維數組並不是零引力。任何想法爲什麼?多維數組是否爲零?
The spec似乎指定多維數組的初始值等於一組一維數組inits,在這種情況下,所有單元應該已經被零點定位。
我跑的測試等同於:
public class Foo {
static int[][] arr;
public static void bar() {
arr = new int[20][20];
// in the second run of Foo.bar(), the value of arr[1][1] is already 1
// before executing the next statement!
arr[1][1] = 1;
}
}
你如何檢查值?無論你運行多少次,我都會看到它總是返回0。 – fmucar 2011-02-14 16:21:37
@fmucar - 這是一個調試器問題 - 請參閱我發佈的答案以獲取更多詳細信息。 – ripper234 2011-02-14 16:36:14
請參閱下面的答案。 – fmucar 2011-02-14 16:53:36