简体   繁体   中英

PropertyChangeSupport with weak references to PropertyChangeListener?

Java does not seem to deliver 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();
      }
  }
}

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