简体   繁体   中英

How do I refer original object values from copied object?

I have cloned an object. Do I have any way to access the original object from copied object?

I have to refer original objects association from copied objects.

No, from cloned object you can't get the original object back but in your method you will have reference to the original object. Eg .

class ClonableClass implements Clonable {

....

 protected Object clone() throws CloneNotSupportedException {
//Code to clone
}
}

class Test {

public testClone(){
    ClonableClass  obj = new ClonableClass (); //Main object
    ClonableClass  cloneObject = (ClonableClass)obj .clone(); //Your clone object
}
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM