Hi, I’m wondering if it’s possible to omit the MainViewModel
type in a code below:
class MainActivity : BaseBoundVmActivity<ActivityMainBinding, MainActivityViewModel>(R.layout.activity_main, MainActivityViewModel::class)
BaseBoundVmActivity.kt:
abstract class BaseBoundVmActivity<out T : ViewDataBinding, out V : ViewModel>(
layoutId: Int,
private val vmClass: KClass<V>
) : BaseBoundActivity<T>(layoutId) {
protected val vm: V by lazy { ViewModelProviders.of(this).get(vmClass.java) }
}
To me it looks unnecessary to provide a second type parameter for a base class when it can be inferred from a parameter in it’s constructor. Is there a way to avoid such duplication?