1700461860
//设置HashMap的值
1700461861
1700461862
public void setValue(String value){
1700461863
1700461864
this.arrayList.add(value);
1700461865
1700461866
}
1700461867
1700461868
//取得arrayList的值
1700461869
1700461870
public ArrayList<String>getValue(){
1700461871
1700461872
return this.arrayList;
1700461873
1700461874
}
1700461875
1700461876
}
1700461877
1700461878
在Thing类中增加一个私有变量arrayLis,类型为ArrayList,然后通过setValue和getValue分别进行设置和取值,我们来看场景类是如何拷贝的,如代码清单13-11所示。
1700461879
1700461880
代码清单13-11 浅拷贝测试
1700461881
1700461882
public class Client{
1700461883
1700461884
public static void main(String[]args){
1700461885
1700461886
//产生一个对象
1700461887
1700461888
Thing thing=new Thing();
1700461889
1700461890
//设置一个值
1700461891
1700461892
thing.setValue(“张三”);
1700461893
1700461894
//拷贝一个对象
1700461895
1700461896
Thing cloneThing=thing.clone();
1700461897
1700461898
cloneThing.setValue(“李四”);
1700461899
1700461900
System.out.println(thing.getValue());
1700461901
1700461902
}
1700461903
1700461904
}
1700461905
1700461906
猜想一下运行结果应该是什么?是仅一个“张三”吗?运行结果如下所示:
1700461907
1700461908
[张三,李四]
1700461909
[
上一页 ]
[ :1.70046186e+09 ]
[
下一页 ]