In this sample(it’s from the Oracle Site) :
// Notify all listeners that have registered interest for
// notification on this event type. The event instance
// is lazily created using the parameters passed into
// the fire method.
protected void fireFooXXX() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==FooListener.class) {
// Lazily create the event:
if (fooEvent == null)
fooEvent = new FooEvent(this);
((FooListener)listeners[i+1]).fooXXX(fooEvent);
}
}
}
What does this
listeners[i]==FooListener.class
Comparison do? It throws me off a bit, since it seems its comparing an instance of a class to a type of class. I would could understand it if it said something like
listeners[i].getClass() == Foolistener.class
But it doesn’t…Can someone enlighten me here? Thanks in advance!
Because that’s what the documentation of getListenerList() says it does.
The array is in pairs of Type and Instance. So index zero is the class (or superclass) of the actual listener found at index 1, index 2 is the class of the actual listener at 3, etc.