2
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)
}
同时拥有compare
和compareTo
是不是有点无用? 我在这里失去的巨大好处是什么?Ordered [A]为什么使用比较方法而不是重用compareTo?
如果他们刚刚使用compareTo
我可以在我的代码中将Comparable
替换为Ordered
并完成。
请问订购前期可比?这很奇怪,但至少有一个实现调用另一个。 – 2010-12-23 18:19:26
命名法。这只是Scala与大Java不同的方式。 – 2010-12-23 20:07:49