Reputation: 95
Say I have something like this:
trait A {
object B {
def doSomething = "test"
}
}
class C extends A {
def out = print(B.doSomething)
}
class D extends A {
// override B.doSomething
}
How do I override the function doSomething
that is inside of object B
?
Upvotes: 3
Views: 6936
Reputation: 67065
This is kind of a duplicate, but of two separate issues:
First, objects are not meant to be overridden. Second, inheriting from a nested class is somewhat straightforward
class A{
class B{
def foo = 1
}
}
class C extends A{
class B extends super.B{
override def foo = 2
}
}
Upvotes: 2