请告知。我认为aobj只有一个副本,除非我们在新对象中添加任何更改或更新最初创建的对象。不确定,请帮忙。
public class AObject {
private String a;
Private String b;
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
}
public class BObject{
private AObject aObj;
public AObject getAObj() {
return aObj;
}
public void setAObj(AObject aObj) {
this.aObj = aObj;
}
}
public static void main(String[] args){
AObject aObj = new AObject();
aObj.setA("testA");
aObj.setB("testB");
BObject bObj = new BObject();
bObj.setAObj(aObj) //here I would like to avoid creating the deep copy of objects.
}
1条答案
按热度按时间yyhrrdl81#
不复制对象。你的代码做你想做的。
(在java中意外地复制某些内容是相当困难的。)