Summary: | [1.5] can't instantiate bounded wildcard | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Igor Fedorenko <igor> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.0 | ||
Target Milestone: | 3.1 M1 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Igor Fedorenko
2004-07-03 19:31:05 EDT
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 |