I had this simple viewmodel provider factory code (borrowed from one of Google's code samples), which happily obliged and compiled perfectly...
fun <VM : ViewModel> viewModelProviderFactoryOf(
create: () -> VM
): ViewModelProvider.Factory = SimpleFactory(create)
private class SimpleFactory<VM : ViewModel>(
private val create: () -> VM
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val vm = create()
if (modelClass.isInstance(vm)) {
@Suppress("UNCHECKED_CAST")
return vm as T
}
throw IllegalArgumentException("Can not create ViewModel for class: $modelClass")
}
}
... Until i introduced this library:
implementation "androidx.navigation:navigation-compose:2.5.0-rc02"
Now all of a sudden compilation fails with:
Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
(error pointing to : ViewModelProvider.Factory )
Why? What did navigation bring in with it? (I did confirm 100% it's the navigation lib causing it, remove it, and the error is gone)
Note: Q is not about how to solve it, compiler suggests it clearly, adding these args - freeCompilerArgs += "-Xjvm-default=all". The Q is about why this is happening.