kotlinx.parcelize.parcelableCreator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-parcelize-runtime Show documentation
Show all versions of kotlin-parcelize-runtime Show documentation
Runtime library for the Parcelize compiler plugin
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("unused")
package kotlinx.parcelize
import android.os.Parcelable
/**
* Read the CREATOR field of the given [Parcelable] class. Calls to this function with
* a concrete class will be optimized to a direct field access.
*/
@Suppress("UNCHECKED_CAST")
inline fun parcelableCreator(): Parcelable.Creator =
T::class.java.getDeclaredField("CREATOR").get(null) as? Parcelable.Creator
?: throw IllegalArgumentException("Could not access CREATOR field in class ${T::class.simpleName}")