ライブラリ クラスのケースunapply
があり、メソッドをオーバーライドして、それに対してパターン マッチングを行うために渡す必要があるパラメータの数を減らしたいと考えています。私はこれをします:
object ws1 {
// a library class
case class MyClass(a: Int, b: String, c: String, d: Double /* and many more ones*/)
// my object I created to override unapply of class MyClass
object MyClass {
def unapply(x: Int) = Some(x)
}
val a = new MyClass(1, "2", "3", 55.0 /* and many more ones*/)
a match {
case MyClass(x /*only the first one is vital*/) => x // java.io.Serializable = (1,2,3,55.0)
case _ => "no"
}
}
しかし、私はそれを返したい1
. これの何が問題なのですか?