Hi guys~!
Consider the following code:
public void reset(int[] arr)
{
for (int i=0;i<arr.length;i++)
{
arr[i]=0;
}
}
I know that regardless of what the actual array is before this method is called it will not change afterward because the method cannot modify it since it is not a local field. My question is why: shouldn't the array still be modified because the array stored at the reference that arr points to is being modified within the method? I know that it isn't modified after this is run, but I want to understand why. Especially since the following DOES modify the array:
public int[] reset(int[] arr)
{
int[] foo = arr;
for (int i=0;i<arr.length;i++)
{
arr[i]=0;
}
return foo;
}