一个呼叫按姓名是expensiveOperation()将不会在下面的例子得到运行好处:斯卡拉的call-by-名字 - 声明参数未使用
呼叫按值:
def test(x: Int, y: Int): Int = x * x
// expensiveOperation is evaluated and the result passed to test()
test(4, expensiveOperation())
的call-by-名称:
def test(x: Int, y: => Int): Int = x * x
// expensionOperation is not evaluated
test(4, expensiveOperation())
我的问题,虽然是你为什么要声明一个函数参数(在我的情况下,y),当你不打算使用它呢?
接不接'y'作为参数?你想要什么 – Jatin
准确!我只是重复Martin Odersky在函数式编程课程中给出的例子 - https://www.coursera.org/course/progfun –