假设我有这样的东西:
trait A {
object B {
def doSomething = "test"
}
}
class C extends A {
def out = print(B.doSomething)
}
class D extends A {
// override B.doSomething
}
如何覆盖 object B
中的函数 doSomething
?
最佳答案
这有点重复,但有两个不同的问题:
首先,objects are not meant to be overridden .二、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
}
}
关于scala - 在 Trait 内覆盖 Object 内的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30227278/