我使用Realm,它需要在其模型类中添加 open
关键字。
根据 https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/,我尝试使用 all-open 编译器插件来移除 Realm 模型类中的 open
关键字。
首先,我添加了 all-open 编译器插件,并设置了注解的包名。
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: "kotlin-allopen"
allOpen {
annotation("com.mycompany.myapp.annotation")
}
第二,我生成了注释。
package com.mycompany.myapp.annotation
annotation class AllOpenAnnotation
最后,我将注释添加到Realm模型类中。
@AllOpenAnnotation
class Model {
var id: Int = -1,
var title: String = "",
var desc: String? = null
}: RealmObject()
但是出现了error: cannot inherit from final Model
错误。
我做错了什么吗?