基本类型传的是复印件
引用类型传的是原件(地址)
![](https://i-blog.csdnimg.cn/blog_migrate/c417d9740bcf4cb1cd79eb4253c5b0f9.png)
Person.java
package com.dym.jvm;
public class Person {
private String personName;
public String getPersonName() {
return personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
public Person(String personName) {
this.personName = personName;
}
public Person() {
}
}
TestTransferValue.java
package com.dym.jvm;
import com.dym.jvm.Person;
public class TestTransferValue {
public void changeValue(int age){
age=30;
}
public void changeValue2(Person person){
person.setPersonName("xxx");
}
public void changeValue3(String str){
str="xxx";
}
public static void main(String[] args) {
TestTransferValue test=new TestTransferValue();
int age=20;
test.changeValue(age);
System.out.println("age------"+age);
Person person=new Person("abc");
test.changeValue2(person);
System.out.println("personName-----"+person.getPersonName());
String str="abc";
test.changeValue3(str);
System.out.println("string-----"+str);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/eb5b2c8c415bdce09f23310aad7813fb.png)