Community
Participate
Working Groups
I am having the following code snippet: public Proposition(String label, WeakValuesMap<String,Object> bindings) { this(label, bindings, (List<IIfClosure>)Collections.emptyList()); } here the "other" constructor with declared argument types String, WeakValuesMap<String,Object> and Collection<IIfClosure> if being called. Thus I want to cast Collections.emptyList() to (List<IIfClosure>) or at least (Collection<IIfClosure>). This however gives me in RC2 the following error: Severity Description Resource In Folder Location Creation Time 2 Cannot cast from List<Object> to List<IIfClosure> Proposition.java set-based-ltl2aa/src/rwth/i2/ltlrv/formula/impl line 80 17. Juni 2005 09:37: 31 Iam pretty much sure that this worked before RC2.
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.