笔者一直错在传递的理解,现在重复记下笔记,加深印象 首篇相关传递的笔记 https://cloud.tencent.com/developer/article/1596896
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";
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有