1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
object Foo {
class S(i: Int)
case class T(i: Int) extends S(i)
object T {
def unapply(s: S): Option[(Int, Int)] = Some(5, 6)
// def unapply(o: Object): Option[(Int, Int, Int)] = Some(5, 6, 7)
}
val s = new S(5)
s match {
// case T(x, y, z) => println(x + y + z)
case T(x, y) => println(x + y)
case T(x) => println(x)
case _ => println("not match")
}
}
object Bar {
case class T(i: Int)
class S(i: Int) extends T(i)
object T {
def unapply(s: S): Option[(Int, Int)] = Some(5, 6)
// def unapply(o: Object): Option[(Int, Int, Int)] = Some(5, 6, 7)
}
val s = new S(5)
s match {
// case T(x, y, z) => println(x + y + z)
case T(x, y) => println(x + y)
case T(x) => println(x)
case _ => println("not match")
}
}
|