Error using toList() of Collectors

Remi Forax forax at univ-mlv.fr
Thu Jan 10 09:40:07 PST 2013


On 01/10/2013 06:29 PM, Venkat Subramaniam wrote:
> (Thinking loud: It would be cool if this can be moved to the static import)

yes, I think you/we should lobby to have IDEs that does automatic static 
import of these methods.
These static methods should be, if all goes as planned, in interface 
Collector,
so it will be easier for IDEs to recognize that these static methods are 
special.

>
> I will certainly try this again once your type inference effort is complete.
>
> Thanks,
>
> Venkat

cheers,
Rémi

>
> On Jan 10, 2013, at 10:21 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>> We are still working on type inference here.
>>
>> You can work around for now with
>>
>>   collect(Collectors.<Integer>toList());
>>
>>
>>
>> On 1/10/2013 12:12 PM, Venkat Subramaniam wrote:
>>> Hello everyone,
>>>
>>> I'm trying to use the new Collectors class.
>>>
>>>      List<Integer> numbers = Arrays.asList(1, 2, 3);
>>>
>>>      //This works
>>>      List<Integer> numbers1 = numbers.stream()
>>>        .collect(toCollection(ArrayList<Integer>::new));
>>>
>>>      //This does not
>>>      List<Integer> numbers2 = numbers.stream()
>>>        .collect(toList());
>>>
>>>      /*
>>>       error: incompatible types: inferred type does not conform to upper bound(s)
>>>            .collect(toList());
>>>                    ^
>>>          inferred: List<Object>
>>>          upper bound(s): List<Integer>,Object
>>>      1 error
>>>      */
>>>
>>> Is this the expected behavior or am I missing something quite basic here?
>>>
>>> Thanks,
>>>
>>> Venkat
>>>
>>>
>



More information about the lambda-dev mailing list