https://kotlinlang.org logo
#android
Title
# android
g

gsala

01/18/2019, 12:31 PM
How can I avoid having the unchecked cast from
VM
to
T
in this:
Copy code
inline fun <reified VM : ViewModel> FragmentActivity.viewModelProvider(crossinline provider: () -> VM) = lazy {
    val factory = object : ViewModelProvider.Factory {
        override fun <T : ViewModel> create(modelClass: Class<T>) =
                provider() as T
    }
    ViewModelProviders.of(this, factory).get(VM::class.java)
}
I would like to have VM and T be the same type
5 Views