如何修复Scala(2.11)中路径相关类型上的类型不匹配错误?
我有这样的代码如何修复Scala(2.11)中路径相关类型上的类型不匹配错误?,scala,Scala,我有这样的代码 trait Toy trait Child { type T <: Toy def toys : Seq[T] def play(toys: Seq[T]): Unit } trait Parent { type C <: Child def firstChild: C } trait Home { def parent: Parent def toys: Seq[Parent#C#T] def a
trait Toy
trait Child {
type T <: Toy
def toys : Seq[T]
def play(toys: Seq[T]): Unit
}
trait Parent {
type C <: Child
def firstChild: C
}
trait Home {
def parent: Parent
def toys: Seq[Parent#C#T]
def apply() = {
val ts = toys
parent.firstChild.play(toys)
}
}
有没有办法在不将所有抽象类型转换为参数类型的情况下修复此错误?使其编译的一种方法是:
trait Toy
trait Child {
type T <: Toy
def toys : Seq[T]
def play(toys: Seq[T]): Unit
}
trait Parent { parent =>
type C <: Child
val firstChild: C
}
trait Home {
val parent: Parent
def toys: Seq[parent.firstChild.T]
def apply() = {
val ts = toys
parent.firstChild.play(toys)
}
}
trait玩具
特质儿童{
T型
类型C使其编译的一种方法是:
trait Toy
trait Child {
type T <: Toy
def toys : Seq[T]
def play(toys: Seq[T]): Unit
}
trait Parent { parent =>
type C <: Child
val firstChild: C
}
trait Home {
val parent: Parent
def toys: Seq[parent.firstChild.T]
def apply() = {
val ts = toys
parent.firstChild.play(toys)
}
}
trait玩具
特质儿童{
T型
C型