假设我有这样的情况:
object Sample02 {
trait A {
def lit = "a"
}
trait B extends A {
def add = lit + " + " + lit
}
trait C extends A {
def sub = lit + " - " + lit
}
def main(args: Array[String]) {
class BA extends B
class CA extends C
val ba = new BA
val ca = new CA
我试过了:
val ls = List(ba, ca)
for (l <- ls)
println(l.lit) //here i can't call "add" and "sub" methods
我怎么能有这样的混合提供?
class BC extends B with C
val bc = new BC
bc.lit
bc.add
bc.sub
}
}
我担心的是,如果我可以避免使用&#34;钻石&#34;继承以便访问三个类中的所有方法 - 更具体地说:没有mixin特性但是使用类?