Tag: 装饰者

我可以使用Java扩展一个Kotlin授权类吗?

我想在Java中扩展一个Kotlin委托类,并得到以下错误: 不能从最终的“派生” 看下面的代码。 我想要做的是装饰一个类的方法。 任何想法为什么Kotlin定义Derived为最终? 有没有办法Derived不是最终的,所以我可以inheritance它? Java的: new Derived(new BaseImpl(10)) { // Getting the error on this line: `Cannot inherit from final ‘Derived’` }; 科特林: interface Base { fun print() } class BaseImpl(val x: Int) : Base { override fun print() { print(x) } } class Derived(b: Base) : Base by b *从这里的例子: https : […]