Override final method

Viewed 5618

Final methods can not be overridden in a subclass. But with the magic of Scala it seems as this is possible.

Consider the following example:

trait Test {
  final def doIt(s: String): String = s
}

object TestObject extends Test {
  def doIt: String => String = s => s.reverse
}

The method doIt in the object TestObject has not the same signature as doIt in trait Test. Thus doIt is overloaded instead of overridden. But a normal call to doIt always calls the method in TestObject:

val x = TestObject.doIt("Hello")                //> x  : String = olleH

Question: How can I call the original method doIt on the TestObject. Is this possible or is this method "sort of overridden"?

3 Answers
Related