Convert old "into" code to the collectors

Paul Sandoz paul.sandoz at oracle.com
Wed Jan 16 07:09:24 PST 2013


On Jan 16, 2013, at 3:34 PM, Marcos Antonio <marcos_antonio_ps at hotmail.com> wrote:

> 
> Hello, everybody!
> 
> Before build b73 I had code like this:
> 
> List<PropriedadeChavePai> propriedades = new ArrayList<>();
> 
> chave.getPropriedadesChavePai().stream().
>    map(PropriedadeChavePai::new).
>    into(propriedades);
> 
> Now I'm having trouble trying to convert it to use the new Collectors. I have tried something like this:
> 
> chave.getPropriedadesChavePai().stream().
>    map(PropriedadeChavePai::new).
>    collect(Collectors.toCollection(propriedades));
> 
> but it didn't work and I couldn't figure out the right thing to do.
> 

What did not work? I suspect compilation. If so try:

  collect(Collectors.<PropriedadeChavePai>toList(propriedades));

Improvements to the compiler type inference are being worked on.

Paul.


More information about the lambda-dev mailing list