This class is used to maintain a list of listeners, and is used in the implementations of several classes within JFace which allow you to register listeners of various kinds. It is a fairly lightweight object, occupying minimal space when no listeners are registered.
Note that the add
method checks for and eliminates duplicates based on identity (not equality). Likewise, the remove
method compares based on identity.
Use the getListeners
method when notifying listeners. Note that no garbage is created if no listeners are registered. The recommended code sequence for notifying all registered listeners of say, FooListener.eventHappened
, is:
Object[] listeners = myListenerList.getListeners(); for (int i = 0; i < listeners.length; ++i) { ((FooListener) listeners[i]).eventHappened(event); }
@deprecated Please use {@link org.eclipse.core.runtime.ListenerList} instead.Please note that the {@link #ListenerList(int)} and{@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}constructors have different semantics. Please read the javadoc carefully. Also note that the equivalent of {@link #ListenerList()} is actually{@link org.eclipse.core.runtime.ListenerList#ListenerList(int)}with {@link org.eclipse.core.runtime.ListenerList#IDENTITY} asthe argument.