In scala multiple inheritance, how to resolve conflicting methods with same signature but different return type?

前端 未结 4 1875
时光说笑
时光说笑 2020-12-17 10:50

Consider the code below:

trait A {
  def work = { \"x\" }
}

trait B {
  def work = { 1 }
}

class C extends A with B {
  override def work = super[A].work
}         


        
4条回答
  •  误落风尘
    2020-12-17 11:09

    Scala simply prevents you from mixing A and B together if they declare a method with the same name and incompatible signature.

提交回复
热议问题