Community
Participate
Working Groups
The following code compiles by javac but not by eclipse. Not sure who's right and who's wrong. =================================================== package test.cheetah; import java.util.HashMap; import java.util.Map; public class NewBoundedWildcard { private static final Map<String, Class<? extends Object>> classes = new HashMap<String, Class<? extends Object>>(); } ====================================================
Forgot to mention, cheetah from CVS, sun jdk 1.5 beta2
This looks like a related problem. The following code compiles with eclipse but not with javac. Looks like javac is correct here. =================================================== package test.cheetah; import java.util.HashMap; import java.util.Map; public class NewBoundedWildcard { private static final Map<String, Class<? extends Object>> classes = new HashMap<String, Class>(); } ===================================================
First issue is due to an extra check for wildcards in invocation, which is no longer necessary once bug 69141 got addressed.
The second scenario feels like it should be allowed, as a raw type is always compatible with a parameterized type. So Map<String,Class> should be assignable to Map<String,Class<? extends Object>>. The following testcase demonstrates this behavior: public class X { class MX<E> { E get() { return null; } void foo(E e) {} } void foo() { MX<Class<? extends Object>> mx1 = new MX<Class<? extends Object>>(); MX<Class> mx2 = new MX<Class>(); mx1.foo(mx2.get()); // unsafe but legite } } Fixed first scenario, added regression test GenericTypeTest#test223