Community
Participate
Working Groups
Code to reproduce bug: class JavaGenericsBug { static class A<T> { T t; A() { } A(T t) { this.t = t; } } static class B<T1 extends A<T2>, T2> { T1 t1; B(T1 t1, T2 t2) { this.t1 = t1; this.t1.t = t2; } <NT2> B<T1, NT2> copyTo(NT2 nt2) { return new B<T1, NT2>(t1, nt2); } } public static void main(String args[]) { B<A<Integer>, Integer> b = new B<A<Integer>, Integer>(new A<Integer>(), 12450); Integer boom = b.copyTo("BOOM!!").t1.t; System.out.print(boom); } } Code on top will cause ClassCastException with no any type cast. And can be compiled without warning.
This is clearly to understand what happened. When try to give a type variable a wildcard type. Compiler dose not fully check the type of wildcard. On this example. Compiler dose not checked whether the wildcard type is compatible with another type variable if them have constraint.
Interesting, T1, when used as a type argument, is not within the bound of T1, when seen as a type parameter. This is not a regression, ecj accepts this code ever since the introduction of generics.
It may be more precise to say that the type B<T1, NT2> is inconsistent, since it would require that "T1 extends A<NT2>" (by substitution of NT2), but that conflicts with the declaration of T1. Not an inference issue.
Just attach another code may related to this issue. public class BugTest<A> { public <T extends Helper1<? extends A>> void foo() { } } class Helper1<A extends Helper2> { } class Helper2 { }
bulk move out of 4.8
Bulk move out of 4.9
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.