1
爲什麼以下工作不能?Scala類型參數綁定錯誤在子類中,但不是超類
scala> class Foo[B<:Foo[B]]
defined class Foo
scala> class Goo[B<:Foo[B]](x: B)
defined class Goo
scala> class Hoo[B<:Hoo[B]] extends Foo[Hoo[B]] { def f = new Goo(this) }
defined class Hoo
scala> class Ioo extends Hoo[Ioo] { def g = new Goo(this) }
<console>:11: error: inferred type arguments [Ioo] do not conform to class Goo's type parameter bounds [B <: Foo[B]]
class Ioo extends Hoo[Ioo] { def g = new Goo(this) }
^
scala> class Ioo extends Hoo[Ioo] { f } // yet this works!
defined class Ioo