soc*_*soc 2 java comparison interop programming-languages scala
trait Ordered[A] extends java.lang.Comparable[A] {
def compare(that: A): Int
def < (that: A): Boolean = (this compare that) < 0
def > (that: A): Boolean = (this compare that) > 0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
def compareTo(that: A): Int = compare(that)
}
Run Code Online (Sandbox Code Playgroud)
是不是有点用处有两个compare
和compareTo
?我在这里失踪的巨大好处是什么?
如果他们刚刚用compareTo
我可能只是取代了Comparable
用Ordered
在我的代码和完成.