0

我对枚举有以下定义:

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

任何人都可以为这个相当神秘的错误信息提供一些解释吗?谢谢

4

1 回答 1

4

Try converting the Set of values for the enum to a List first like so:

val dataSets = (GraphType.values.toList.map(gt => (gt, new TimeSeries(gt)))).toMap

Something about that being a Set did not agree with how you were attempting to convert it to a Map, but it seems to work just fine with a List

于 2013-05-08T16:11:26.650 回答