I use Realm and it requires open
keyword to it's model classes.
Following https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/,
I tried to use all-open compiler plugin to remove the open
keyword from Realm model classes.
First, I added all-open compiler plugin and set the package name of annotation
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: "kotlin-allopen"
allOpen {
annotation("com.mycompany.myapp.annotation")
}
Second, I generated annotation
package com.mycompany.myapp.annotation
annotation class AllOpenAnnotation
Finally, I added the annotation to Realm model class
@AllOpenAnnotation
class Model {
var id: Int = -1,
var title: String = "",
var desc: String? = null
}: RealmObject()
But the error: cannot inherit from final Model
error occurs.
Is there something that I did wrong?
You need to add the name of the annotation to the path in your config file:
allOpen {
annotation("com.mycompany.myapp.annotation.AllOpenAnnotation")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With