English 中文(简体)
二级,但不包括超级
原标题:Scala type parameter bound error in subclass but not superclass
  • 时间:2011-07-27 18:11:10
  •  标签:
  • 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
最佳回答

。 这是Ioo,因此我们需要<代码>。 Ioo <: Foo[Ioo]。

问题回答

暂无回答




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签