I am using a Kotlin data class with Realm, Gson annotation for fetching Data from server.
Problem: When i run project in android studio it gives following error
Error:Class "VenderConfig" contains illegal final field "name".
I am learning Kotlin so don't have much idea about that.
My VenderConfig
class is:
@RealmClass
class VenderConfig(
@SerializedName("name")
val name: String? = null,
@SerializedName("website")
val wb_url: String? = null,
@SerializedName("icon")
val icon: String? = null,
@SerializedName("logo")
val logo: String? = null,
@SerializedName("description")
val description: String? = null,
@PrimaryKey
@SerializedName("id")
val id: Int? = null
) : RealmObject() {
}
I have also tried open keyword with the field and remove data keyword also, but it did not solve the issue.
You should use var
keyword to declare mutable properties. val
stands for immutable (final) ones.
var name: String? = null
name = "Kotlin" // OK
val immutableName: String? = null
immutableName = "Java" // won't compile, val cannot be reassigned
For more info: Properties and Fields
Notice that I'm not familiar with Realm and this may not solve your problem.
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