考虑这个课程:
class DateTime(year: Int, month: Int, day: Int)(hour: Int, minute: Int, second: Int)
Run Code Online (Sandbox Code Playgroud)
该unapply
方法将如何,如果我想匹配以下内容:
dt match {
case DateTime(2012, 12, 12)(12, _, _) => // December 12th 2012, 12 o'clock
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
def unapply(dt: DateTime) =
Some((dt.year, dt.month, dt.day),(dt.hour, dt.minute, dt.second))
Run Code Online (Sandbox Code Playgroud)
但这并没有真正起作用.