我正在从这里上课:https://dagger.dev/tutorial/07-two-for-the-price-of-one
当我更改代码时
@Module
abstract class HelloWorldModule {
@Binds
abstract fun helloWorldCommand(command: HelloWorldCommand): Command
}
进入
@Module
abstract class HelloWorldModule {
@Binds
@IntoMap
@StringKey("hello")
abstract fun helloWorldCommand(command: HelloWorldCommand): Command
}
我遇到错误:
error: [Dagger/MissingBinding] Map<String,? extends Command>
cannot be provided without an @Provides-annotated method.
我在这里想念的是什么?它不适用于Kotlin吗?
谢谢@David Medenjak
,您是对的!上面的代码还可以,问题是缺少@JvmSuppressWildcards
,所以我的课程CommandRouter
现在看起来像:
@JvmSuppressWildcards
class CommandRouter @Inject constructor(
val outputter: Outputter,
val commands: Map<String, Command>
) {
// ...
}