Bug 100527 - [1.5] False error message: Cannot cast from List<Object> to List<IIfClosure>
Summary: [1.5] False error message: Cannot cast from List<Object> to List<IIfClosure>
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 RC3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-17 03:43 EDT by Eric Bodden CLA
Modified: 2005-06-23 14:35 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Bodden CLA 2005-06-17 03:43:13 EDT
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.
Comment 1 Olivier Thomann CLA 2005-06-17 09:32:52 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 
Comment 2 Philipe Mulet CLA 2005-06-17 09:37:24 EDT
Added GenericTypeTest#test763.

We indeed were missing a couple checks until recently.
This code is invalid.
Comment 3 Philipe Mulet CLA 2005-06-17 09:44:01 EDT
To be more explicit, this is a consequence of addressed bug 97800
Comment 4 Eric Bodden CLA 2005-06-18 08:05:02 EDT
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.)
Comment 5 Philipe Mulet CLA 2005-06-18 14:49:47 EDT
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>).
Comment 6 Eric Bodden CLA 2005-06-23 13:54:02 EDT
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...
Comment 7 Philipe Mulet CLA 2005-06-23 14:35:15 EDT
Right, but this is bypassing inference completely.