4
在Twitter's Scala schoolcollections section,他们表现出了部分功能的值地图:斯卡拉地图的部分功能价值
// timesTwo() was defined earlier.
def timesTwo(i: Int): Int = i * 2
Map("timesTwo" -> timesTwo(_))
如果我尝试使用Scala 2.9.1和sbt我得到这个编译如下:
[error] ... missing parameter type for expanded function ((x$1) => "timesTwo".$minus$greater(timesTwo(x$1)))
[error] Map("timesTwo" -> timesTwo(_))
[error] ^
[error] one error found
如果我添加的参数类型:
Map("timesTwo" -> timesTwo(_: Int))
然后我得到以下编译器错误:
[error] ... type mismatch;
[error] found : Int => (java.lang.String, Int)
[error] required: (?, ?)
[error] Map("timesTwo" -> timesTwo(_: Int))
[error] ^
[error] one error found
我很难过。我错过了什么?
或'地图( “timesTwo” - >(timesTwo _))' – 2012-03-23 05:41:23
或'地图[字符串,INT => INT]( “timesTwo” - > timesTwo) ' – sschaef 2012-03-23 13:33:19