scala.collection.immutable.NumericRange.Inclusive - >设置[字符] - >设置[字符串]?

时间:2016-06-06 14:53:14

标签: scala

以下两个命令创建Set[Char],然后map - 根据需要提供Set[String]

scala> ('a' to 'z').toSet
res15: scala.collection.immutable.Set[Char] = Set(e, s, ...)

scala> res15.map(_.toString)
res16: scala.collection.immutable.Set[String] = Set(e, s, ...)

但为什么以下不起作用?

scala> ('a' to 'z').toSet.map(_.toString)
<console>:12: error: missing parameter type for expanded 
     function ((x$1) => x$1.toString)('a' to 'z').toSet.map(_.toString)

1 个答案:

答案 0 :(得分:0)

此替代方案完美无缺:

 ('a' to 'z').toSet[Char].map(_.toString)

这是因为toSet接受[B >: A]类型参数,并且无法直接推断调用toString的类型