的集合映射函数接受序列[字符]我可以定义一个接受Seq[Char]
斯卡拉:我为什么不能在字符串
def f(s: Seq[Char]) = s
函数,如果我通过在String
它的工作原理:
scala> f("this")
res8: Seq[Char] = this
这意味着我可以在map
使用它:
scala> List("this").map(s => f(s))
res9: List[Seq[Char]] = List(this)
那么,为什么我不能做到这一点?:
scala> List("this").map(f)
<console>:10: error: type mismatch;
found : Seq[Char] => Seq[Char]
required: java.lang.String => ?
List("this").map(f)
^
我有一种感觉,它与两步隐式转换限制有关。感谢您的解释! – dhg 2012-08-04 19:39:03