fc013c6b9f
Fixes KT-19853. The CREATOR field is a static field on a Parcelable class which is not visible from Kotlin since the necessary metadata would have to be in a Companion object which may not exist. This commit adds a [parcelableCreator] function to kotlinx.parcelize, which is optimized to a direct field access whenever possible.
28 lines
687 B
Kotlin
Vendored
28 lines
687 B
Kotlin
Vendored
// See https://issuetracker.google.com/174827004
|
|
// WITH_RUNTIME
|
|
|
|
@file:JvmName("TestKt")
|
|
package test
|
|
|
|
import kotlinx.parcelize.*
|
|
import android.os.Bundle
|
|
import android.os.Parcel
|
|
import android.os.Parcelable
|
|
|
|
@Parcelize
|
|
class Section<T : Parcelable>(val title: String, val faTitle: T) : Parcelable
|
|
|
|
fun box() = parcelTest { parcel ->
|
|
val test = Section<Bundle>("title", Bundle())
|
|
test.writeToParcel(parcel, 0)
|
|
|
|
val bytes = parcel.marshall()
|
|
parcel.unmarshall(bytes, 0, bytes.size)
|
|
parcel.setDataPosition(0)
|
|
|
|
val test2 = parcelableCreator<Section<Bundle>>().createFromParcel(parcel)
|
|
|
|
assert(test.title == test2.title)
|
|
assert(test2.faTitle.size() == 0)
|
|
}
|