Why can't a class extend traits with method of the same signature?

后端 未结 5 2153
旧时难觅i
旧时难觅i 2020-12-23 12:02

Why do I get the error below? How to workaround it?

I assumed that since A and B compile to (interface,class) pairs, it\'s a matter of choosing the right static meth

5条回答
  •  醉话见心
    2020-12-23 12:38

    This works for me in 2.8 and 2.11, and would allow you to be non-intrusive in traits A or B:

    trait A { def hi = println("A") }
    trait B { def hi = println("B") }
    
    class C extends A with B {
      override def hi = super[B].hi
      def howdy = super[A].hi // if you still want A#hi available
    }
    
    object App extends Application {
      (new C).hi // prints "B"
    }
    

提交回复
热议问题