【发布时间】:2016-11-30 01:45:29
【问题描述】:
以下是 Scala 隐式类的示例程序:
object Run {
implicit class IntTimes(x: Int) {
def times [A](f: =>A): Unit = {
def loop(current: Int): Unit =
if(current > 0){
f
loop(current - 1)
}
loop(x)
}
}
}
还有一个类叫“4 times println("hello")”如下,但我不明白“4 times println("hello")”是什么意思?
object Demo {
def main(args: Array[String]) {
4 times println("hello")
}
}
【问题讨论】:
-
这个可以叫'times(4) println("hello")'
标签: scala