在下面,我有一個類CurryDefaultDemo
在構造函數中帶有一個參數,並且該參數有一個默認值,它是一個curried函數。curried函數中的默認參數
scala> object Demo {
|
| type myF = String => Int
|
| def f(x: Int = 1)(y: String) = x + y.toInt
|
| }
defined module Demo
scala> import Demo._
import Demo._
scala> class CurryDefaultDemo(fun: myF = f())
defined class CurryDefaultDemo
如由默認值f()
被f
更換,我得到以下錯誤:
scala> class CurryDefaultDemo(fun: myF = f)
<console>:11: error: type mismatch;
found : String => Int
required: Int
class CurryDefaultDemo(fun: myF = f)
^
我知道f
將是一個局部的功能String => Int
。 「required:Int」來自哪裏?