【发布时间】:2014-06-26 06:12:52
【问题描述】:
在下面,我有一个类CurryDefaultDemo,在构造函数中有一个参数,该参数有一个默认值,它是一个柯里化函数。
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。
“必需:Int”从何而来?
【问题讨论】:
标签: scala