rook
01/15/2021, 4:39 PMrook
01/15/2021, 4:42 PMval myBundleString: String by BundleDelegate.of(MY_BUNDLE_STRING_KEY)
Joel
01/15/2021, 10:06 PMreturn extras.get(key)?.let { clazz.cast(it) } ?: throw Exception("Key does not exist in bundle.")
This will throw a ClassCastException
if the value is not clazz
, and you don't have an unchecked cast.rook
01/15/2021, 10:31 PMClassCastException
Joel
01/15/2021, 10:32 PMActivity
Joel
01/15/2021, 10:33 PMinline fun <reified T> Activity.fromBundle(key: String) = lazy {
intent.extras[key] as? T ?: throw Exception("Key does not exist in bundle")
}
rook
01/16/2021, 4:38 AM