Question about MapStream.intoMulti
François Sarradin
fsarradin at gmail.com
Sat May 5 06:02:30 PDT 2012
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