src/share/classes/javax/swing/event/EventListenerList.java

Print this page

        

@@ -139,15 +139,18 @@
      * @since 1.3
      */
     public <T extends EventListener> T[] getListeners(Class<T> t) {
         Object[] lList = listenerList;
         int n = getListenerCount(lList, t);
+        @SuppressWarnings("unchecked")
         T[] result = (T[])Array.newInstance(t, n);
         int j = 0;
         for (int i = lList.length-2; i>=0; i-=2) {
             if (lList[i] == t) {
-                result[j++] = (T)lList[i+1];
+                @SuppressWarnings("unchecked")
+                T tmp = (T)lList[i+1];
+                result[j++] = tmp;
             }
         }
         return result;
     }
 

@@ -170,11 +173,11 @@
     public int getListenerCount(Class<?> t) {
         Object[] lList = listenerList;
         return getListenerCount(lList, t);
     }
 
-    private int getListenerCount(Object[] list, Class t) {
+    private int getListenerCount(Object[] list, Class<?> t) {
         int count = 0;
         for (int i = 0; i < list.length; i+=2) {
             if (t == (Class)list[i])
                 count++;
         }

@@ -286,11 +289,13 @@
         while (null != (listenerTypeOrNull = s.readObject())) {
             ClassLoader cl = Thread.currentThread().getContextClassLoader();
             EventListener l = (EventListener)s.readObject();
             String name = (String) listenerTypeOrNull;
             ReflectUtil.checkPackageAccess(name);
-            add((Class<EventListener>)Class.forName(name, true, cl), l);
+            @SuppressWarnings("unchecked")
+            Class<EventListener> tmp = (Class<EventListener>)Class.forName(name, true, cl);
+            add(tmp, l);
         }
     }
 
     /**
      * Returns a string representation of the EventListenerList.