# 上界（Upper bound）、下界（Lower bound）、視界（View bound）

``class Animalclass Human extends Animalclass Toyclass Duck[T <: Animal]val ad = new Duck[Animal]val hd = new Duck[Human]val td = new Duck[Toy]     // 編譯錯誤，不符型態邊界``

``def quick(list: List[Int]): List[Int] = {    list match {        case Nil => Nil             case x::xs =>                val (before,after) = xs partition (_ < x)        quick(before) ++ (x :: quick(after))    }}``

``def quick[T <: Ordered[T]](list: List[T]): List[T] = {    list match {        case Nil => Nil             case x::xs =>                val (before,after) = xs partition (_ < x)        quick(before) ++ (x :: quick(after))    }}``

``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    override def toString = "Ball(" + radius + ")"}val bs = List(new Ball(3), new Ball(2), new Ball(4), new Ball(1))quick(bs).foreach(println)``

``class Alienclass Kryptonian extends Alienclass Earthmanclass Spiderman extends Earthmanclass Superman[T >: Kryptonian]val s1 = new Superman[Kryptonian]val s2 = new Superman[Alien]val s3 = new Superman[Spiderman]  // 編譯錯誤，不符型態邊界``

``def quick[T <: Ordered[T]](list: List[T]): List[T] = {    list match {        case Nil => Nil             case x::xs =>                val (before,after) = xs partition (_ < x)        quick(before) ++ (x :: quick(after))    }}val list = List(3, 1, 2, 4)quick(list).foreach(println)``

``def quick[T <% Ordered[T]](list: List[T]): List[T] = {    list match {        case Nil => Nil             case x::xs =>                val (before,after) = xs partition (_ < x)        quick(before) ++ (x :: quick(after))    }}val list1 = List(3, 1, 2, 4)quick(list1).foreach(println)val list2 = List("xyz", "xab", "abc", "cde")quick(list2).foreach(println)``