以下两个命令创建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)
答案 0 :(得分:0)
此替代方案完美无缺:
('a' to 'z').toSet[Char].map(_.toString)
这是因为toSet
接受[B >: A]
类型参数,并且无法直接推断调用toString
的类型