为什么这不起作用:
scala> trait A
defined trait A
scala> class Z {
| this: A =>
| }
defined class Z
scala> class Y {
| this: A =>
| val z = new Z()
| }
<console>:11: error: class Z cannot be instantiated because it does not conform to its self-type Z with A
val z = new Z()
我希望混入 Y 中的 A 再次混入 Y 中 Z 的实例中。我该怎么做?
编辑(在上面的例子中试图过于简短。这是我的实际问题):
scala> import scala.slick.driver.ExtendedProfile
import scala.slick.driver.ExtendedProfile
scala> class Z {
| this: ExtendedProfile =>
| }
defined class Z
scala> class Y {
| this: ExtendedProfile =>
| val z = new Z() with ExtendedProfile
| }
<console>:21: error: illegal inheritance;
self-type Z with scala.slick.driver.ExtendedProfile does not conform to scala.slick.driver.ExtendedProfile's selftype scala.slick.driver.ExtendedDriver
val z = new Z() with ExtendedProfile
^
我想我理解为什么不能编译,但这不应该是隐式的(不是实际的 scala 关键字'隐式',只是一般隐式;))?如果一个 ExtendedProfile 总是必须有一个 ExtendedDriver,为什么 new Z() 抱怨它需要一个 ExtendedDriver?
仅供参考:http ://slick.typesafe.com/doc/1.0.0-RC1/api/#scala.slick.driver.ExtendedProfile