For the code below, as far as I understand, the linearization of the expression
new E with D with C with B
- E โ C โ B โ D. So, then there should be no expression d.foo () in the code
ECBD instead of CBDE is rated lower. What am I missing?
trait A { def foo(): String = "" } trait B extends A { abstract override def foo() = "B" + super.foo() } trait C extends B { abstract override def foo() = "C" + super.foo() } trait D extends A { abstract override def foo() = "D" + super.foo() } class E extends A{ override def foo() = "E" } var d = new E with D with C with B; d.foo()
I noticed that if I have class F as below
class F extends A with D with C with B{ override def foo() = "F" + super.foo() }
and do
new F().foo
he prints "FCBD"
It seems a little incompatible with me, because the class F mixes the same way as the expression, but has a different print order
scala traits
Abdul rahman
source share