你如何返回一个成员变量(包含对象)
- 没有低效复制(在内存中复制)成员变量的对象
然后重置成员变量
- 没有覆盖返回的成员变量的对象,让观察者获得之前的“副本”?
这是一个示例代码:
public class SomeClass extends Observable {
private Object someObject;
private void whenSomethingHappens() {
this.setChanged();
this.notifyObservers(someObject); // TODO: return the object without copying it in RAM
this.someObject = new Object(); // TODO: create a new empty object somwhere else in RAM such as it doesn't override the returned object of before
}
}