【发布时间】:2012-01-28 02:56:16
【问题描述】:
在第 410 页的“Scala 编程,第二版”中,您可以找到具有以下方法的类 Simulation:
private def next() {
(agenda: @unchecked) match {
case item :: rest =>
agenda = rest
curtime = item.time
item.action()
}
}
我很好奇为什么 Odersky 使用模式匹配来实现这一点,而不是这样:
private def next() {
val item = agenda.head
agenda = agenda.tail
curtime = item.time
item.action()
}
模式匹配是否如此高效以至于根本无关紧要? 或者它只是不是那么完美的例子?
【问题讨论】:
标签: scala pattern-matching scala-2.8 scala-collections