I've used auto generated feature of android plugin for android studio and it generated me the following code, but I can't understand why is there need for final val
for CREATOR
field ? I see final
keyword for the first time in kotlin.
data class Person(
val name: String,
val surname: String
) : Parcelable {
constructor(source: Parcel): this(source.readString(), source.readString())
override fun describeContents(): Int {
return 0
}
override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(name)
dest?.writeString(surname)
}
companion object {
@JvmField final val CREATOR: Parcelable.Creator<Person> = object : Parcelable.Creator<Person> {
override fun createFromParcel(source: Parcel): Person {
return Person(source)
}
override fun newArray(size: Int): Array<Person?> {
return arrayOfNulls(size)
}
}
}
}