override fun <T : ViewModel> create(modelClass: Class<T>): T = when {
modelClass.isAssignableFrom(M1ViewModel::class.java) -> M1ViewModel(dataManager, schedulerProvider)
modelClass.isAssignableFrom(C1ViewModel::class.java) -> C1ViewModel(dataManager, schedulerProvider)
modelClass.isAssignableFrom(C2ViewModel::class.java) -> C2ViewModel(dataManager, schedulerProvider)
else -> throw IllegalArgumentException("Unknown ViewModel class: " + modelClass.name)
} as T
这是代码
怎样才能把代码最小化,这样就不用每次都写了
modelClass.isAssignableFrom(C2ViewModel::class.java) -> C2ViewModel(dataManager, schedulerProvider)
我能够像这样实现它。
PS不是签名者,只是切换到java和kotlin