Summary: | [1.5] False error message: Cannot cast from List<Object> to List<IIfClosure> | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Eric Bodden <eric> |
Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
Status: | RESOLVED INVALID | QA Contact: | |
Severity: | major | ||
Priority: | P3 | ||
Version: | 3.1 | ||
Target Milestone: | 3.1 RC3 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Eric Bodden
2005-06-17 03:43:13 EDT
test case: import java.util.*; interface IIfClosure {} public class X { public X(String label, HashMap<String,Object> bindings) { this(label, bindings, (List<IIfClosure>)Collections.emptyList()); } public X(String label, HashMap<String,Object> bindings, Collection<IIfClosure> coll) { } } javac fails as well: X.java:7: inconvertible types found : java.util.List<java.lang.Object> required: java.util.List<IIfClosure> this(label, bindings, (List<IIfClosure>)Collections.emptyList()); ^ 1 error Added GenericTypeTest#test763. We indeed were missing a couple checks until recently. This code is invalid. To be more explicit, this is a consequence of addressed bug 97800 Hmmm insteresting and thanks for pointing that out. So does anybody know how to correctly produce a typed empty collection using the collections classes then? (I mean apart from creating a new one.) In this very case you are in trouble. The normal way is to use a temp variable as an intermediate. There the assignment will provide input for inferring the right return type, but a cast is not judged as a good hint by the spec (i.e. blame the spec <g>). Just for your information: There *is* actually a solution for my original problem, as I learned today: public X(String label, HashMap<String,Object> bindings) { this(label, bindings, Collections.<IIfClosure>emptyList()); } I wasn't even aware of this notation, but apparently it works... Right, but this is bypassing inference completely. |