[英]Java Observer Pattern not notifying
For some reason my observers are not being notified when i call the notifyObserver methods, using the java.util.Observable objects: 出于某种原因,当我使用java.util.Observable对象调用notifyObserver方法时,我的观察者没有得到通知:
here is my observable object: 这是我的可观察对象:
public class ProjectManager extends Observable
{
...
public void updateProjects(String project, String pack, String source, String ARN)
{
...
if(newSource)
{
tempPack.add(tempSource);
System.out.println("Notify observers: " + this.countObservers());
this.notifyObservers();
}
...
}
i can see from my output that the observer is being added but not being notified. 我可以从我的输出中看到观察者正在被添加但没有得到通知。
and my observer object looks like this: 我的观察者对象看起来像这样:
public class IDE implements Observer
{
@Override
public void update(Observable o, Object arg) {
System.out.println("Notified");
}
For some strange reason the observable object is not being notified at all. 由于某些奇怪的原因,可观察对象根本没有得到通知。 Am i doing something wrong here?
我在这里做错了吗?
在notifyObservers
之前,您需要setChanged
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.