The following code snippet
class A {
def foo = "A.foo"
}
trait B {
def foo = "B.foo"
def bar = "B.bar"
}
val x = new A with B
not compiled because
error: overriding method foo in class A of type => java.lang.String;
method foo in trait B of type => java.lang.String needs `override' modifier
However, my intention is defined as follows:
x.foo => "A.foo"
x.bar => "B.par"
That is, I want x to inherit the bar from B, but not foo. Is there a way in scala to achieve this?
source
share