我似乎不能创建一个也混合在SynchronizedSet中的SortedSet。问题的症结在于SortedSet需要一个隐式排序对象。
val orderByIdThenName = Ordering[(Int, String)].on[Foo](foo => foo.id -> foo.name)
new mutable.TreeSet[Foo]()(orderByIdThenName) // <- Works fine and is Ordered
new mutable.HashSet[Foo] with mutable.SynchronizedSet[Foo] // <- Mixin works
new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo] // Fail!最后一行给出错误"Object creation Object,因为scala.collection.SortedSetLike中的成员OrderingA未定义。
有什么建议吗?
发布于 2013-04-12 11:45:02
这看起来是IntelliJ中的一个错误。我能够重现这个问题,并在编辑器中看到错误,但在编译时没有出现错误或警告。
因为没有给出orderByCount的定义,所以我假设它是这样的:
val orderByCount = Ordering[Int].on[Foo](_.count)
new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo]更新:想出了一种通过覆盖ordering来消除IntelliJ中的错误的方法
new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo] {
implicit override val ordering: Ordering[Foo] = orderByCount
}https://stackoverflow.com/questions/15962490
复制相似问题