【发布时间】:2017-01-04 19:11:18
【问题描述】:
我使用 Realm,它的模型类需要 open 关键字。
关注https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/,
我尝试使用全开放编译器插件从 Realm 模型类中删除 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 错误。
是不是我做错了什么?
【问题讨论】:
标签: kotlin