作為共用實作的特徵

``class Ball(val radius: Int) {    def volume = 4 * Math.Pi * Math.pow(radius, 3) / 3    def < (that: Ball) = this.radius - that.radius < 0    def <=(that: Ball) = (this < that) || (this == that)    def > (that: Ball) = !(this <= that)    def >=(that: Ball) = !(this < that)    override def equals(a: Any) = a match {        case that: Ball => this.radius == that.radius;        case _ => false    }    override def hashCode = 41 * radius}``

``trait Ordered {    def compare(that: Any): Int    def < (that: Any) = compare(that) < 0    def <=(that: Any) = (this < that) || (this == that)    def > (that: Any) = !(this <= that)    def >=(that: Any) = !(this < that)}``

``class Ball(val radius: Int) extends Ordered {    def volume = 4 * Math.Pi * Math.pow(radius, 3) / 3    def compare(a: Any) = a match {        case that: Ball => this.radius - that.radius;        case _ => throw new IllegalArgumentException("不是球比什麼？")    }    override def equals(a: Any) = a match {        case that: Ball => this.radius == that.radius;        case _ => false    }    override def hashCode = 41 * radius}val b1 = new Ball(10)val b2 = new Ball(20)println(b1 > b2)       // falseprintln(b1 >= b2)      // falseprintln(b1 < b2)       // trueprintln(b1 <= b2)      // trueprintln(b1 == b2)      // false``

package scala

trait Ordered[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)
}

Ordered[A]可以在使用時宣告A的型態，例如，上例可以使用Ordered[A]來改寫如下，而結果仍相同：
``class Ball(val radius: Int) extends Ordered[Ball] {    def volume = 4 * Math.Pi * Math.pow(radius, 3) / 3    def compare(that: Ball) = this.radius - that.radius    override def equals(a: Any) = a match {        case that: Ball => this.radius == that.radius;        case _ => false    }    override def hashCode = 41 * radius}val b1 = new Ball(10)val b2 = new Ball(20)println(b1 > b2)       // falseprintln(b1 >= b2)      // falseprintln(b1 < b2)       // trueprintln(b1 <= b2)      // trueprintln(b1 == b2)      // false``