hg: lambda/lambda/jdk: 8009736: Comparator to allow narrowing type on combinator APIs

Michael Hixson michael.hixson at gmail.com
Sun Mar 10 15:17:50 PDT 2013


Hi Henry,

In the places where the return type is being narrowed, I believe you
need to use the subtype <S> in the generics of the method arguments as
well.  Otherwise the narrowed return type doesn't do much.  For
example:

  default <S extends T> Comparator<S> thenComparing(Comparator<? super T> other)

That should be:

  default <S extends T> Comparator<S> thenComparing(Comparator<? super S> other)

The same change should be applied to the first argument of all the
thenComparing methods.

(If you start with a Comparator<Object>, you should be able to combine
it with a Comparator<String> or Function<String, U> to produce another
Comparator<String>.  Without using the type <S> in the arguments, the
current signatures restrict you to combining it only with other
Comparator<Object> and Function<Object, U>.)

-Michael

On Sat, Mar 9, 2013 at 10:27 PM,  <henry.jen at oracle.com> wrote:
> Changeset: fb7b7275d220
> Author:    henryjen
> Date:      2013-03-08 21:54 -0800
> URL:       http://hg.openjdk.java.net/lambda/lambda/jdk/rev/fb7b7275d220
>
> 8009736: Comparator to allow narrowing type on combinator APIs
> Reviewed-by:
> Summary: Allow to narrow return type, add javadoc return tag
> Allow key extract not limited to Comparable, but use a Comparator of key type.
>
> ! src/share/classes/java/util/Comparator.java
> ! src/share/classes/java/util/Comparators.java
>
>


More information about the lambda-dev mailing list