简体   繁体   中英

Make scala.Long Comparable

I have a following function which requires T to extend Comparable. scala.Long is not comparable as it is representing Java's primitive version.

  • What is the best way to make scala.Long comparable without changing the type?
  • Is there a way to get Comparable[scala.Long] without having to define one myself?
    public static <T extends Comparable<? super T>> Combine<T> ordering() {}

You could wrap your scala.Long in a Comparable wrapper, and use that class:

public static class ScalaLongWrapper implements Comparable<scala.Long>{
     public scala.Long v;

     public ScalaLongWrapper(scala.Long l){
         this.v = l;
     }

     public int compareTo(scala.Long l){
         return this.v - l;
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM