【发布时间】:2013-12-22 21:28:12
【问题描述】:
看Scala 2.10.0在LinearSeqOptimized.scala中对LinearSeqOptimized#find的实现,为什么一定要调用var these = this呢?
为什么不能简单地使用this?
override /*IterableLike*/
def find(p: A => Boolean): Option[A] = {
var these = this
while (!these.isEmpty) {
if (p(these.head)) return Some(these.head)
these = these.tail
}
None
}
【问题讨论】:
标签: algorithm scala collections