final方法不能在子类中被重写,但是借助Scala的魔力,似乎这是有可能的。
考虑下面的示例:
trait Test {
final def doIt(s: String): String = s
}
object TestObject extends Test {
def doIt: String => String = s => s.reverse
}
对象 TestObject
中的方法 doIt
与特质 Test
中的 doIt
没有相同的签名。因此,doIt
是重载而不是覆盖。但是对 doIt
的普通调用始终调用 TestObject
中的方法:
val x = TestObject.doIt("Hello") //> x : String = olleH
问题:
如何调用TestObject
上原始的doIt
方法?是否可能或者该方法被“覆盖”了?