我有一个枚举的以下定义:
object GraphType extends Enumeration {
type Type = Value
val MESSAGE, REQUEST, ERRORS = Value
}
现在我尝试将每种类型映射到相应的新TimeSeries
,如下所示:
val dataSets = ( GraphType.values map (graphType => graphType -> new TimeSeries(graphType)) ).toMap
类型系统将数据集列为Map[GraphType.Value, TimeSeries]
,这正是我想要的。但是,编译失败并显示错误消息:
error: diverging implicit expansion for type scala.collection.generic.CanBuildFrom[ird.replay.gui.GraphType.ValueSet,(ird.replay.gui.GraphType.Value, org.jfree.data.time.TimeSeries),That]
starting with method newCanBuildFrom in object SortedSet
val dataSets = GraphType.values map (graphType => graphType -> new TimeSeries(graphType)) toMap
COuld有人为此提供了一些解释,相当神秘,错误消息?感谢
答案 0 :(得分:2)
首先尝试将枚举的值集转换为List
,如下所示:
val dataSets = (GraphType.values.toList.map(gt => (gt, new TimeSeries(gt)))).toMap
有关作为套装的内容与您尝试将其转换为Map
的方式不一致,但它似乎与List