1

I'm doing lesson from here: https://dagger.dev/tutorial/07-two-for-the-price-of-one

When I'm changing code

@Module
abstract class HelloWorldModule {
    @Binds
    abstract fun helloWorldCommand(command: HelloWorldCommand): Command
}

into

@Module
abstract class HelloWorldModule {
    @Binds
    @IntoMap
    @StringKey("hello")
    abstract fun helloWorldCommand(command: HelloWorldCommand): Command
}

I'm getting error:

error: [Dagger/MissingBinding] Map<String,? extends Command> 
cannot be provided without an @Provides-annotated method.

What I'm missing here? It won't work on Kotlin?

thorin86
  • 604
  • 11
  • 26
  • 2
    Probably [`@JvmSuppressWildcards`](https://stackoverflow.com/a/46043372/1837367) depending on the dagger version you're using – David Medenjak Mar 20 '20 at 20:57

1 Answers1

4

Thanks @David Medenjak, you were right! Above code is ok, the problem was with missing @JvmSuppressWildcards, so my class CommandRouter now looks like:

@JvmSuppressWildcards
class CommandRouter @Inject constructor(
    val outputter: Outputter,
    val commands: Map<String, Command>
) {
// ...
}
thorin86
  • 604
  • 11
  • 26