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"?
You can use TestObject
as Test
like this:
(TestObject: Test).doIt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With