Demo for Parallel Core Collection API

Paul Sandoz paul.sandoz at oracle.com
Tue Oct 15 07:55:18 PDT 2013


On Oct 15, 2013, at 4:20 PM, Tristan Yan <tristan.yan at oracle.com> wrote:

> Thank you Paul
> 
> There is one minor question, I can't compile one of your code, then I realized that's because grouping by signature is public static <T, K, A, D>
>    Collector<T, ?, Map<K, D>> groupingBy(Function<? super T, ? extends K> classifier, Collector<? super T, A, D> downstream) 
> 
> Which makes me wonder why we need type A here, why we don't use variant here. Why the method signature is not
>    public static <T, K, D> Collector<T, ?, Map<K, D>> groupingBy(Function<? super T, ? extends K> classifier, Collector<? super T, ?, D> downstream)
> 
> I do remember there was a discussion about this, but I couldn't find the answer for this.
> 
> Code can't be passed compilation
>        return products.stream().
>                //collect products into a Map, which key is S by function of
>                //groupFunc, value is max or min by given max and function of
>                //compFunc
>                collect(groupingBy(
>                        groupFunc,
>                        maxBy ? maxBy(comp) : minBy(comp)));
> 

Drat, i just assumed that since the IDE did not show squiggly red lines that it would compile.

Downstream receiving collectors refer to the intermediate accumulation type, so we should abstract what it is, be it a ? or something else of the downstream collector.

Unfortunately in this case it looks like the compiler is thrown off the scent by ternary operator. If you remove the operator and just express say "minBy(comp)" it should compile.

I don't know whether this is something that can be fixed in the compiler or not.

Paul.


More information about the lambda-dev mailing list