# 參數化型態的物件相等性

``class Basket[T](val things: T*) {    override def equals(a : Any) = a match {        case that: Basket[T] => this.things.toArray                                 deepEquals                                that.things.toArray        case _               => false    }}``

warning: there were unchecked warnings; re-run with -unchecked for details

warning: non variable type-argument T in type pattern is unchecked since it is eliminated by erasure
case that: Basket[T] => this.things.toArray deepEquals that.things.toArray

``class Basket[T](val things: T*) {    override def equals(a : Any) = a match {        case that: Basket[_] => this.things.toArray deepEquals                                that.things.toArray        case _               => false    }}``

``val b1 = new Basket(1, 2)val b2 = new Basket(1, 2)val b3 = new Basket(2, 2)val b4 = new Basket("1", "2")println(b1 == b2)       // trueprintln(b1 == b3)       // falseprintln(b1 == b4)       // false``

``val b1 = new Basket[Int]val b2 = new Basket[String]println(b1 == b2)   // true``

``val l1: List[Int] = Nil    val l2: List[String] = Nilprintln(l1 == l2)   // true``
``class Basket[T](val things: T*) {    override def equals(a : Any) = a match {        case that: Basket[_] => (that canEquals this) &&                                (this.things.toArray deepEquals                                 that.things.toArray)        case _               => false    }    def canEquals(other: Any) = other.isInstanceOf[Basket[_]]    override def hashCode = 41 * (1 /: things.toArray) {_ * 41 + _.hashCode}                             + things.hashCode}``