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();
}
}
}
精彩评论