我是新來斯卡拉,今天我看到了一個函數定義我無法理解:scala中的這些測量是什麼?
def f(x: Int): Int = x
val func = (x: Int, y: Int, z: Int) => f(x)
於是在Scala中,什麼是定義func
的語法?對我而言,func
只是一個接受三個參數的函數:func: (Int, Int, Int) => Int = <function3>
。爲什麼不只是將func
定義爲
def func(x: Int, y: Int, z: Int): Int = f(x)
這是出於效率的原因嗎?因爲我們只需要評估一次val。
http://stackoverflow.com/questions/18887264/what-is-the-difference-between-def-and-val-to-define-a-function查看接受的答案的最後一段。 – vptheron 2014-09-03 14:35:28