android / android-ktx

A set of Kotlin extensions for Android app development.
https://android.github.io/android-ktx/core-ktx/
7.46k stars 563 forks source link

bundleOf() does not support SparseParcelableArray #563

Closed nhaarman closed 6 years ago

nhaarman commented 6 years ago

Bundle has putSparseParcelableArray, but the bundleOf() function does not support this:

bundleOf("foo" to SparseArray<Parcelable>())

Error:

Caused by: java.lang.IllegalArgumentException: Illegal value type android.util.SparseArray for key "foo"
    at androidx.core.os.BundleKt.bundleOf(Bundle.kt:99)
JakeWharton commented 6 years ago

Erasure prevents validating the generic type is bound by Parcelable. This should be solved by #263 where the call site will change slightly to be fully type-safe.