Community
Participate
Working Groups
Build ID: I20080617-2000 See simple code below. It compiles under Eclipse, but neither of the calls to "buz" pass javac. "baz" is only presented as a frame of reference, since javac and Eclipse seem to agree on that. ****************************** import java.util.List; public class Foo { private static class C {} private static class B<T extends C> {} private static class A<T extends B<? extends C>> {} void bar (List<A> a) { baz((List)a); // Neither of these two following statements compile under javac buz(a); buz((List)a); // Side note: the following statement is correctly identified as an error // by Eclipse, but it does not suggest casting as a Quick Fix. // baz(a); } <R extends C, T extends B<R>> void baz(List<A<T>> a) {} <R extends C, T extends B<R>> void buz(List a) {} }
I suspect this is a bug in javac, where the inference in JLS 15.12.2.8 doesn't properly exploit formal upper bounds. This combined with JLS 15.12.2.6 (unchecked conversion involved in invocation arguments) is likely accounting for the difference in behavior for javac between #baz(...) and #buz(...) invocations. I believe both invocations are fine, and we should accept them.
Added GenericTypeTest#test1443. Closing as invalid.
Re: // but it does not suggest casting as a Quick Fix. Quickfix is only trying to fix code correctly. The quickfix you suggested would turn bad code in unsafe code; resulting into an unchecked invocation warning. It should rather be turned into correct code, which cannot be trivially determined here.
Verified for 3.5M5