我有以下基类和接口
open class Base {
open fun foo() { println("Base.foo") }
}
fun interface Delegate {
fun foo(): Unit
}
现在,我想使用委托重写Base
子类Composed
的foo
方法,如下所示:
class Composed(delegate: Delegate) : Base(), Delegate by delegate
这是我想要的.Composed
的实例使用delegate
的foo
方法,而不是Base
的方法.But,我收到IntelliJ的警告:
委托成员"fun foo():Unit"隐藏超类型重写:public open fun foo():在基中定义的单元.请明确指定正确的覆盖.
为什么会出现此错误?隐式重写foo
方法的"坏处"是什么?有什么缺点我看不出来吗?显式指定重写似乎有很多不必要的代码,特别是如果我对多个方法和多个子类这样做的话.