编译器正在尝试查找
R
的类型参数
Stream#map
map
是一个
Function[String,Int]
,并且它必须与
Function[_ >: String, _ <: R]
地图
),这是有限制的
Int <: R
R <: Object
(至少我认为是这样的)。所以没有合适的方法
R
要修复,正如我在评论中提到的,您可以使用
mapToInt
,但实际上还有一个更糟糕的错误消息,它肯定应该被修复(我报告了一个问题):指定
map[Int]
导致
type mismatch;
found : Array[Int]
required: Array[Int]
Note: Int >: Int, but class Array is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10)