似乎可以更改具有如下特征的类上的方法的实现:
trait Abstract { self: Result =>
override def userRepr = "abstract"
}
abstract class Result {
def userRepr: String = "wtv"
}
case class ValDefResult(name: String) extends Result {
override def userRepr = name
}
val a = new ValDefResult("asd") with Abstract
a.userRepr
此处提供实时代码:http ://www.scalakata.com/52534e2fe4b0b1a1c4daa436
但现在我想调用函数的先前或超级实现,如下所示:
trait Abstract { self: Result =>
override def userRepr = "abstract" + self.userRepr
}
或者
trait Abstract { self: Result =>
override def userRepr = "abstract" + super.userRepr
}
但是,这些替代方案都不能编译。知道如何实现吗?