Java参数传递有两种形式,值传递和引用传递。
一、值传递:
值传递只是将原数据的一份拷贝传递过去,修改的只是拷贝数据,原数据不做修改。
二、引用传递:
传递的是数据地址,即会修改原数据。
三、String
String虽然也是引用类型,但是其也是按照值传递来进行的。
public class Test {
public static void main(String[] args)
{
Test test=new Test();
String s="hello";
System.out.println(s);
test.change(s);
System.out.println(s);
}
public String change(String name)
{
name="world";
return name+"word";
}
}
hello
hello
原文:http://blog.csdn.net/fengzhongzhishenfu/article/details/24552415