class A{ def m(s:String) = println(s"A($s)") } trait B extends A{ override def m(s:String) = super.m(s"B($s)") } trait C extends A{ override def m(s:String) = super.m(s"C($s)") } trait D extends A{ override def m(s:String) = super.m(s"D($s)") } trait E extends C{ override def m(s:String) = super.m(s"E($s)") } trait F extends C{ override def m(s:String) = super.m(s"F($s)") } class G extends D with E with F with B{ override def m(s:String) = super.m(s"G($s)") } val x = new G x.m("")
step | 結果 |
---|---|
1 | G B A |
2 | G B A F C A |
3 | G B A F C A E C A |
4 | G B A F C A E C A D A |
5 | G B F C E C D A |
6 | G B F E C D A |
7 | G B F E C D A AnyRef Any |
因此輸出應該是:css
A(D(C(E(F(B(G()))))))
ide
step | 結果 |
---|---|
1 | G D A |
2 | G E C D A |
3 | G F E C D A |
4 | G B F E C D A |
5 | G B F E C D A AnyRef Any |
因此輸出應該是:spa
A(D(C(E(F(B(G()))))))