Given Foo
:
class Foo {
def getBar = new Bar
class Bar {
def baz = 3
}
}
I'd like to be able to extend Foo
, and override baz
.
The simplest implementation I can think of is this:
class Foo2 extends Foo {
override def getBar = new Bar2
class Bar2 extends Bar {
override def baz = 5
}
}
but I'm wondering if there is a simpler way to achieve this.
(getBar
might contain a lot of code, and I don't won't to copy paste it with just a small change Bar
-> Bar2
)
I tried this:
class Foo2 {
class Bar extends super.Bar {
override def baz = 5
}
}
But unfortunately it doesn't work
(new Foo2().getBar.baz == 3
)
Any other ideas?
Update: fixed compilation error as mentioned in the responses