Error using toList() of Collectors

Michael Nascimento misterm at gmail.com
Thu Jan 10 09:16:51 PST 2013


Probably you have to explicitly specify the type parameter <Integer>... sigh...

Regards,
Michael

On Thu, Jan 10, 2013 at 3:12 PM, Venkat Subramaniam
<venkats at agiledeveloper.com> 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