Name: dsC58869 Date: 09/14/99
JDK1.3 javadoc for java.awt.Component.getListeners(Class) states:
/**
* Return an array of all the listeners that were added to the Component
* with addXXXListener(), where XXX is the name of the <code>listenerType</code>
* argument. For example, to get all of the MouseListeners for the
* given Component <code>c</code>, one would write:
* <pre>
* MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class))
* </pre>
* If no such listener list exists, then an empty array is returned.
*
* @param listenerType Type of listeners requested
* @returns an array of all listeners added to this Component using addXXXListener, or an empty array if no such listeners have been added to this Component.
* @since 1.3
*/
Javadoc says nothing about ClassCastException thrown if class is not
subclass of the java.util.EventListener.
Here is a minimized test:
--- ComponentTest.java ---
import java.awt.*;
import java.util.*;
public class ComponentTest {
public static void main (String[] args) {
Canvas c = new Canvas();
EventListener[] l = c.getListeners(Object.class);
}
}
--- Output ---
java ComponentTest
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
at java.awt.AWTEventMulticaster.getListeners(AWTEventMulticaster.java:799)
at java.awt.Component.getListeners(Component.java:3211)
at ComponentTest.main(ComponentTest.java:6)
======================================================================