Hi. I'm in the middle of porting some new samples from Google to Kotlin and I'm stuck with an `@Into...
a
Hi. I'm in the middle of porting some new samples from Google to Kotlin and I'm stuck with an
@IntoMap
bindings. Having this module:
Copy code
@Module
abstract class ViewModelModule {

    @Binds
    @IntoMap
    @ViewModelKey(MainActivityViewModel::class)
    abstract fun bindMainActivityViewModel(mainActivityViewModel: MainActivityViewModel): ViewModel

    @Binds
    abstract fun bindViewModelFactory(factory: InjectingViewModelFactory): ViewModelProvider.Factory
}
and this class:
Copy code
@Singleton
class InjectingViewModelFactory @Inject constructor(
        private val viewModelProviders: Map<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory
I get an error:
app\build\tmp\kapt3\stubs\debug\com\example\myapp\di\AppComponent.java5 error: [dagger.android.AndroidInjector.inject(T)] java.util.Map<java.lang.Class<? extends android.arch.lifecycle.ViewModel>,? extends javax.inject.Provider<android.arch.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method.
And when I change the implementation of
InjectingViewModelFactory
to Java like this:
Copy code
@Singleton
public class InjectingViewModelFactory implements ViewModelProvider.Factory {
    private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;

    @Inject
    public InjectingViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
        this.creators = creators;
    }
}
it works OK. Can you please tell me what I'm doing wrong?