对象赋值
来源:互联网 发布:qq强制视频软件 编辑:程序博客网 时间:2024/06/07 00:12
代码:
public void test() throws Exception {Student student1 = new Student(),student2 = new Student(),student3 = new Student();student1.setFk_Group_Id("1");student2.setFk_Group_Id("2");List<Student> list = new ArrayList<>();student3 = student1;list.add(student1);student1.setFk_Group_Id("11");System.out.println("list中的student1:"+list.get(0).getFk_Group_Id());System.out.println("student3:"+student3.getFk_Group_Id()+"/n重新赋值");student3.setFk_Group_Id("33");student3 = student2;System.out.println("list中的student1:"+list.get(0).getFk_Group_Id());System.out.println("student1:"+student1.getFk_Group_Id());System.out.println("student2:"+student2.getFk_Group_Id());System.out.println("student3:"+student3.getFk_Group_Id());}
结果:
list中的student1:11
student3:11/n重新赋值
list中的student1:33
student1:33
student2:2
student3:2
说明:
list.add(student1);则如果student1改了,list里面的student1也会改变,相当于共享一个对象引用。
student3 = student1;是student1和student3将共享一个对象引用,所以改了student3,student1也会
改变。
student3 = student2;则student2和student3将共享一个对象引用了
0 0
- 对象赋值
- 对象赋值
- 给const对象赋值
- javascript中的对象赋值
- 对象赋值注意事项
- 对象赋值测试
- 对象用等号赋值
- Java中的对象赋值!!!!
- 对象的赋值
- java对象类赋值
- Java中的对象赋值!!!! .
- 对象的赋值
- 为对象动态赋值
- 对象赋值与复制
- 对象初始及赋值
- c++对象赋值运算
- PHP对象赋值详解
- 对象赋值的疑惑
- TabHost的底部实现
- 下载文件名乱码
- VS2010/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- 引导页实现
- oracle函数trunc的使用
- 对象赋值
- VS2010/MFC编程入门之二十二(常用控件:按钮控件的编程实例)
- sql ORACLE(七):视图、序列
- android listview item 点击无效解决
- Web前端性能优化——CSS优化
- Java单例模式解析
- VS2010/MFC编程入门之二十三(常用控件:列表框控件ListBox)
- U-Mail邮件系统客户无需担心OpenSSL心脏出血漏洞
- 局部变量作为返回值问题