class ClosureClass {
def printResult[T](f: => T) = {
println("choice 1")
println(f)
}
def printResult[T](f: String => T) = {
println("choice 2")
println(f("HI THERE"))
}
}
object demo {
def main(args: Array[String]) {
val cc = new ClosureClass
cc.printResult() // call 1
cc.printResult("Hi") // call 2
}
}
我玩上面的代码,结果给我看。我有两个问题
1) 为什么一号电话和二号电话 都进入选择1?
2) 我如何通过参数才能进入选择 2。
谢谢
choice 1
()
choice 1
Hi