考虑这个类:
class DateTime(year: Int, month: Int, day: Int)(hour: Int, minute: Int, second: Int)
如果我想匹配以下内容,该unapply
方法会是什么样子:
dt match {
case DateTime(2012, 12, 12)(12, _, _) => // December 12th 2012, 12 o'clock
/* ... */
}
我试过这个:
def unapply(dt: DateTime) =
Some((dt.year, dt.month, dt.day),(dt.hour, dt.minute, dt.second))
但这并没有真正奏效。