简体   繁体   English

使scala.Long可比

[英]Make scala.Long Comparable

I have a following function which requires T to extend Comparable. 我有以下函数,需要T扩展Comparable。 scala.Long is not comparable as it is representing Java's primitive version. scala.Long不具有可比性,因为它表示Java的原始版本。

  • What is the best way to make scala.Long comparable without changing the type? 在不更改类型的情况下使scala.Long可比的最佳方法是什么?
  • Is there a way to get Comparable[scala.Long] without having to define one myself? 有没有一种方法可以不必自己定义就获得Comparable [scala.Long]?
    public static <T extends Comparable<? super T>> Combine<T> ordering() {}

You could wrap your scala.Long in a Comparable wrapper, and use that class: 您可以将scala.Long用Comparable包装器包装,然后使用该类:

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;
     }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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