J
Josef Garvi
I have trouble cloning a descendant of Observable.
I would like to make a deep copy, so I've overridden the clone() method so
that it clones all fields correctly.
However, my new clone gets the same observer connections as the original.
What is worse, if I try to disconnect the observers from my clone by
writing something like:
protected Object clone() throws CloneNotSupportedException {
MyObject cl = (MyObject)super.clone();
System.out.println("Observers before: " + countObservers());
cl.deleteObservers();
System.out.println("Observers after: " + countObservers());
return cl;
}
(the two println commands display the number of observers connected to my
*original* object)
....I lose all the connections from my Observers to my original object as
well. in other words, the cloned object does not seem to be capable of
holding an observer list of its own....?
Any way to get around this?
TIA
--
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
I would like to make a deep copy, so I've overridden the clone() method so
that it clones all fields correctly.
However, my new clone gets the same observer connections as the original.
What is worse, if I try to disconnect the observers from my clone by
writing something like:
protected Object clone() throws CloneNotSupportedException {
MyObject cl = (MyObject)super.clone();
System.out.println("Observers before: " + countObservers());
cl.deleteObservers();
System.out.println("Observers after: " + countObservers());
return cl;
}
(the two println commands display the number of observers connected to my
*original* object)
....I lose all the connections from my Observers to my original object as
well. in other words, the cloned object does not seem to be capable of
holding an observer list of its own....?
Any way to get around this?
TIA
--
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty