Question about MapStream.intoMulti
Rémi Forax
forax at univ-mlv.fr
Sat May 5 06:53:12 PDT 2012
I think it's a bug in the signature of intoMulti,
instead of
<A extends Map<? super K, C>,C extends Collection<? super V>> A
intoMulti(A destination, Factory<C> factory)
it should be
<A extends Map<? super K, C>,C extends Collection<? super V>> A
intoMulti(A destination, Factory<? extends C> factory)
Rémi
On 05/05/2012 03:02 PM, François Sarradin 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