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. }
You do not copy the object. Your code does what you want.
(It is pretty difficult to accidentally copy something in Java.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.