I’m looking if it is possible to use reified for c...
# announcements
e
I’m looking if it is possible to use reified for class instantiation. I tried code like:
Copy code
class BaseFragment<T: BaseViewModel> {
  val viewModel: T = createViewModel()
}

private fun <reified T: BaseViewModel> createViewModel() = T::java.class.newInstance()
This compiles but I have just one function with BaseViewModel class as argument. Is it possible to get many such methods for every class that extends it with more specific view model?
f
You can't use reified at a class level generic type. However you can make one abstract/open class and every other that implements it will have that method available.
e
Do you have a reference or example?
I wanted to avoid to write in every subclass method to provide specific class name