@Composablepublicinlinefun<reifiedVM:ViewModel>viewModel(viewModelStoreOwner:ViewModelStoreOwner=checkNotNull(LocalViewModelStoreOwner.current){"No ViewModelStoreOwner was provided via LocalViewModelStoreOwner"key:String?=null,factory:ViewModelProvider.Factory?=null):VM=viewModel(VM::class.java,viewModelStoreOwner,key,factory)
It has 3 parameters, and it calls another viewModel(), but let's simplify this view model creation for the sake of understanding this reified.
and you want to create an instance of MyViewModel by its class type (i.e. MyViewModel::Class.java), you want to call (MyViewModel::class.java).getDeclaredConstructor().newInstance().
To make it a helper function, you create the following:
You cannot use T::class.java directly, thus you need to pass in as Class<T> parameter into the viewModel() function.
This limitation is called Type erasure because the JVM platform doesn't support generic types. The generic type is lost when we compile Kotlin to JVM bytecode.
However, Kotlin overcomes this limitation with Reified type parameter.