トレイト内で共変型パラメーターを使用して、次のようなケースクラスを構築しようとしています:
trait MyTrait[+T] {
private case class MyClass(c: T)
}
コンパイラは次のように述べています。
error: covariant type T occurs in contravariant position in type T of value c
次に、次のことを試しましたが、うまくいきませんでした。
trait MyTrait[+T] {
private case class MyClass[U <: T](c: U)
}
今回のエラーは次のとおりです。
error: covariant type T occurs in contravariant position in type >: Nothing <: T of type U
ここでTが共変の位置にある理由を誰かが説明し、この問題の解決策を提案できますか? どうも!