1

SynchronizedSet にも混在する SortedSet を作成できないようです。問題の核心は、SortedSet が暗黙の Ordering オブジェクトを必要とすることです。

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!

最後の行で、「scala.collection.SortedSetLike のメンバ Ordering[A] が定義されていないため、オブジェクトの作成は不可能です。

助言がありますか?

4

1 に答える 1

0

これは IntelliJ のバグのようです。問題を再現してエディターでエラーを確認できましたが、コンパイル時にエラーや警告はありません。

orderByCount の定義が指定されていないため、次のようなものであると想定しています。

val orderByCount = Ordering[Int].on[Foo](_.count)
new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo]

更新: IntelliJ のエラーをオーバーライドして解決する方法を考え出しましたordering:

new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo] {
    implicit override val ordering: Ordering[Foo] = orderByCount
}
于 2013-04-12T03:45:01.880 に答える