Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 533049

Summary: Generics with Lists.NewArrayList generates an Error. Works with Javac.
Product: [Eclipse Project] JDT Reporter: Luca Masera <luca.masera79>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.7.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug

Description Luca Masera CLA 2018-03-29 04:54:47 EDT
When I write the following code: 

---------------------------------------------------------------------
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

...


public List<? extends MyBaseType> getMyTypeList() {
    return Lists.newArrayList(Iterables.concat(
                                    getMyTypeA(), 
                                    getMyTypeB().iterator());
}

...

---------------------------------------------------------------------


I get this error:
Error:(171, 16) java: Type mismatch: cannot convert from java.util.ArrayList<java.lang.Object> to java.util.List<? extends MyType>



With this code I get instead no error: 

---------------------------------------------------------------------
... // same imports

public List<? extends ExtOrgMapping> getPersonLists() {
    Iterator<? extends ExtOrgMapping> iterator = 
                          Iterables.concat(getMyTypeA(),                                                                   
                                           getMyTypeB()).iterator();

    return Lists.newArrayList(iterator);
}

...

---------------------------------------------------------------------
Comment 1 Luca Masera CLA 2018-03-29 05:01:16 EDT
I've forgot, both the functions 

getMyTypeA() and getMyTypeB()

return a sub-type of MyBaseType. 

And, of course, the second function sample uses the MyBaseType.
Comment 2 Eclipse Genie CLA 2020-04-03 06:12:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Stephan Herrmann CLA 2020-04-03 13:43:58 EDT
@Luca, if you disagree with this bug being closed, please provide a complete compilable example (no paraphrasing please, plain Java). I started to fill in the dots, but then noticed that the most crucial part is missing even from the verbal description: what is the exact type of

    getMyTypeB().iterator()

?