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

(reflect) Bad interaction between generic signatures, inner classes, and reflection

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Cannot Reproduce
    • 5.0
    • None
    • core-libs

    Description

      The following program demonstrates a problem with generics, inner classes
      and reflection:

      $ cat -n Test.java
           1
           2 import java.lang.reflect.Field;
           3 import java.lang.reflect.Type;
           4
           5 public class Test
           6 {
           7 p1.Test3.Inner<Integer> _field;
           8
           9 public static void main(String[] args) throws Exception {
          10 Class test = Test.class;
          11 Field f = test.getDeclaredField("_field");
          12 Type t = f.getGenericType();
          13 System.out.println("type = " + t);
          14 }
          15
          16 }
      $ cat -n Test3.java
           1 package p1;
           2
           3 public class Test3 {
           4 public class Inner<T> { T get() { return null; } }
           5 }
      $ javac -d . Test.java Test3.java
      $ java -cp . Test
      type = p1.Test3.p1.Test3$Inner<java.lang.Integer>


      The output is wrong and should have been:

      type = p1.Test3$Inner<java.lang.Integer>

      The signature generated by javac might be undesirable, but it
      follows the spec.


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: