What does the following error message mean?
cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent ``accidental overrides'');
I was trying to do stackable trait modifications. It's a little bit after the fact since I already have a hierarchy in place and I'm trying to modify the behavior without having to rewrite a lot of code.
I have a base class called AbstractProcessor that defines an abstract method sort of like this:
abstract class AbstractProcessor {
def onPush(i:Info): Unit
}
I have a couple existing traits, to implement different onPush behaviors.
trait Pass1 {
def onPush(i:Info): Unit = { /* stuff */ }
}
trait Pass2 {
def onPush(i:Info): Unit = { /* stuff */ }
}
So that allows me to use new AbstractProcessor with Pass1
or new AbstractProcessor with Pass2
.
Now I would like to do some processing before and after the onPush call in Pass1 and Pass2 while minimizing code changes to AbstractProcessor and Pass1 and Pass2. I thought of creating a trait that does something like this:
trait Custom extends AbstractProcessor {
abstract override def onPush(i:Info): Unit = {
// do stuff before
super.onPush(i)
// do stuff after
}
}
And using it with new AbstractProcessor with Pass1 with Custom
and I got that error message.
The problem is that there is ambiguity between AbstractProcessor.onPush
and Pass1.onPush
. The latter is not overridding the former because Pass1
does not extend AbstractProcessor
.
If you make Pass1
and Pass2
extend AbstractProcessor
, then the problem is solved.
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