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

(reflect) toGenericString fails to print bounds of type variables on generic methods

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b19
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      As demonstrated by the program below, java.lang.reflect.Method.toGenericString
      doesn't print bounds on type variables on generic methods. Run the program like this:

      $ java Test java.util.Collections max java.util.Collection java.util.Collections
      max
      java.util.Collection
      public static <T> T java.util.Collections.max(java.util.Collection<? extends T>)

      The output should have been:

      max
      java.util.Collection
      public static <T extends Object & Comparable<? super T>> T java.util.Collections.max(java.util.Collection<? extends T>)

      import java.lang.reflect.*;
       
      public class Test {
          public static void main(String... args) throws ClassNotFoundException, NoSuchMethodException {
              for (int i=0; i<args.length; i++) System.out.println(args[i]);
              String cName = args[0];
              String mName = args[1];
              Class<?> c = Class.forName(cName);
              Class<?>[] cs = new Class<?>[args.length - 2];
              for (int i=0; i<args.length-2; i++) cs[i] = Class.forName(args[i+2]);
              Method m = c.getMethod(mName, cs);
              System.out.println(m.toGenericString());
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              ahe Peter Ahe
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: