不,因为您没有分配给数组,而是分配给了名为的临时变量
i。阵列看不到更改。
下面显示了使用普通
for循环的大致等效代码。这应该使您更容易了解为什么无法更新阵列:
for (int j = 0; j < numbers.length; j++) { Integer i = arr[j]; // i is null here. i = counter++; // Assigns to i. Does not assign to the array.}
不,因为您没有分配给数组,而是分配给了名为的临时变量
i。阵列看不到更改。
下面显示了使用普通
for循环的大致等效代码。这应该使您更容易了解为什么无法更新阵列:
for (int j = 0; j < numbers.length; j++) { Integer i = arr[j]; // i is null here. i = counter++; // Assigns to i. Does not assign to the array.}