hg: lambda/lambda/jdk: Override reverse() for NullComparator

Peter Levart peter.levart at gmail.com
Tue Jun 25 02:21:51 PDT 2013


Hi Henry,

I think there's also a possibility to override 
Collections.ReverseComparator.reversed(), like that:

         @Override
         public Comparator<Comparable<Object>> reversed() {
             return Comparator.naturalOrder();
         }


More complete solution would be to add an if statement in 
Collections.reverseOrder(Comparator):

     public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
         ...

         if (cmp == ReverseComparator.REVERSE_ORDER)
             return (Comparator<T>) 
Comparators.NaturalOrderComparator.INSTANCE;
         ...
     }


But that could make code compiled with JDK7 and only run on JDK8 produce 
serialized streams that are not compatible with JDK7. Overriding just 
the ReverseComparator.reversed() method only affects code that is 
compiled on JDK8, since this is new method.

Regards, Peter

On 05/10/2013 08:47 AM, henry.jen at oracle.com wrote:
> Changeset: 6d9e66f573f6
> Author:    henryjen
> Date:      2013-05-09 23:47 -0700
> URL:       http://hg.openjdk.java.net/lambda/lambda/jdk/rev/6d9e66f573f6
>
> Override reverse() for NullComparator
>
> ! src/share/classes/java/util/Comparators.java
> ! test/java/util/Comparator/BasicTest.java
>
>



More information about the lambda-dev mailing list