Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6176471

(reflect) Extend Class.forName with class tokens

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • 6
    • 6
    • core-libs
    • None

      Please extend the typing of java.lang.Class.forName by adding either a static method:

      public static <U> Class<? extends U> forName(String className, Class<U> bound) {
         return bound.cast(forName(className));
      }

      Or a non-static method:

      public Class<? extends T> forSubclassName(String className) {
         return cast(forName(className));
      }

      This would help in situations like:

      import java.util.EventListener;
      import javax.swing.event.EventListenerList;

      class Test {
          void test(String name, EventListenerList list, EventListener l)
      throws ClassNotFoundException
          {
      list.add((Class)Class.forName(name), l);
          }
      }
      ###@###.### 10/8/04 21:34 GMT

            ahe Peter Ahe
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: