1
def task() {
Thread.sleep(60*1000) // update lru cache every minute
// do some compute-intensive task here to populate lru cache
println("LRU Updated!")
}
new Thread {
override def run = while(true) task()
}.start
而(..)VSIterator.continually VS斯卡拉
Iterator.continually(task()).dropWhile(_=>true)
具有完全相同的行爲。它們在引擎蓋下等價嗎?
這取決於你的意思是「等價」。它們絕對不會導致相同的字節碼,「持續」版本的開銷更大。 – wingedsubmariner