开发者

PropertyChangeSupport with weak references to PropertyChangeListener?

Java does not seem to del开发者_Python百科iver an implementation of PropertyChangeSupport with weak references to registered PropertyChangeListeners.

It would not be very hard to implement this, but before I re-invent the wheel, does anyone know whether such feature has been implemented in any open source library? It does not seem so, but someone may know better on SO.


Would this Netbeans WeakListeners page help ?

Example:

public class Observer {
  private Listener listener;

  private void registerTo(Source source) {
      listener = new Listener();
      source.addChangeListener(WeakListeners.change (listener, source));
  }

  private class Listener implements ChangeListener {
      public void stateChanged(ChangeEvent e) {
          doSomething();
      }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜