class TestIt
{
public static void main ( String[] args )
{
int[] myArray = {1, 2, 3, 4, 5};
ChangeIt.doIt( myArray );
for(int j=0; j<myArray.length; j++)
System.out.print( myArray[j] + " " );
}
}
class ChangeIt
{
static void doIt( int[] z )
{
if(z.length>0)z[0]=8;
z = null ;
}
}
这个输出的结果是8 2 3 4 5.
我知道对象或数组作为参数传递时,传递的是一个引用,将z[0]赋值为8直接将z指向的数组{1, 2, 3, 4, 5}第一个元素改为8,但是将z指向null为什么就变成值传递了呢