笔者一直错在传递的理解,现在重复记下笔记,加深印象
public static void main(String[] args) throws IOException {
int num = 0;
change(num); // num = 0
}
public static void change(int n){
n = 1;
}
public static void main(String[] args) throws IOException {
String str = "default";
str = "change"; // str = "change"
}
public static void main(String[] args) throws IOException {
String str = "default";
change(str); // str = "default"
}
public static void change(String s){
s = "change";
}
改变u的指向不会影响user,但如果改变u指向实例的内容name,那么就会影响到user了
public static void main(String[] args) throws IOException {
User user = new User("default");
change(user); // user.name = "change"
}
public static void change(User u){
u.name = "change";
}
原文:https://www.cnblogs.com/Howlet/p/12803736.html