我可以使用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 : //kotlinlang.org/docs/reference/delegation.html
Kotlin课程默认是最终的 。 将这个类标记为open
(无论是从Kotlin还是从Java):
open class Derived(b: Base) : Base by b
这是委托类的事实应该没有影响Java互操作(虽然我没有尝试过)。
- 我在android项目中使用这个库,但使用https://github.com/igalata/Bubble-Picker/错误
- 使用Kotlin无法在项目中设置Realm
- Java类名中的Kotlin中的静态常量
- 通过委托对象在Groovy中实现抽象类
- Android:stopService在另一个Activity中
- 如何将kotlin类或kotlin类实例作为参数传递
- android -kotlin -java.lang.ClassCastException
- 将java类文件转换为kotlin会导致编译错误
- IntelliJ IDEA使用Gradle构建文件中指定的依赖关系的JavaScript“版本”?