-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
5.0
-
generic
-
generic
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.
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.
- relates to
-
JDK-8054213 Class name repeated in output of Type.toString()
-
- Closed
-
-
JDK-6476261 (reflect) GenericSignatureFormatError When signature includes nested inner classes
-
- Closed
-
-
JDK-6832374 (reflect) malformed signature can cause parser to go into infinite loop
-
- Closed
-