Question about MapStream.intoMulti

François Sarradin fsarradin at gmail.com
Sun May 6 02:07:20 PDT 2012


Thank for your answers.

At present, I suppose it is better to play with MapStream only and not to
try to convert them into Map. Unless by doing it "by hand"?

Regards,

Francois Sarradin

2012/5/5 Brian Goetz <brian.goetz at oracle.com>

> This one is a leftover from when we had a separate stream shape for
> multimap.   Now you can simulate this with
>
> mapStream.mapValues(v -> singletonList(v))
>
> Sent from my iPhone
>
> On May 5, 2012, at 6:02 AM, François Sarradin <fsarradin at gmail.com> wrote:
>
> > Hi all,
> >
> > I would like to know what is the purpose of the method
> MapStream.intoMulti?
> > Is it convert a MapStream into a Map of Collection[s] ?
> >
> > Here is an example that I have tried with this method:
> >
> >    public static Map<DevelopmentStage, Collection<Person>>
> > distribute(Iterable<Person> persons) {
> >        return persons
> >                     .groupBy(Age::getDevelopmentStage)
> >                     .intoMulti(
> >                         new HashMap<DevelopmentStage,
> > Collection<Person>>(),
> >                         () -> new ArrayList<Person>());
> >    }
> >
> > But this code generates this error:
> >
> > error: method intoMulti in interface MapStream<K,V> cannot be applied to
> > given types;
> > required: A,Factory<C>
> > found: HashMap<DevelopmentStage,Collection<Person>>,lambda
> > reason: invalid inferred types for A,C
> > reason: inferred type does not conform to declared bound(s)
> > inferred: HashMap<DevelopmentStage,Collection<Person>>
> > bound(s): Map<? super DevelopmentStage,ArrayList<Person>>
> > where A,C,V,K are type-variables:
> > A extends Map<? super DevelopmentStage,C> declared in method
> > <A,C>intoMulti(A,Factory<C>)
> > C extends Collection<? super V> declared in method
> > <A,C>intoMulti(A,Factory<C>)
> > V extends Object declared in interface MapStream
> > K extends Object declared in interface MapStream
> >
> > Am I wrong ? Why the lambda expression is not inferred into
> > Factory<Collection<Person>> ?
> >
> > Thanks,
> >
> > Francois Sarradin
> >
>


More information about the lambda-dev mailing list