kotlin - Dagger2 和 Kotlin:@Binds 不适用于 @IntoMap
问题描述
我正在从这里学习: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
,你是对的!上面的代码没问题,问题是 missing @JvmSuppressWildcards
,所以我的课CommandRouter
现在看起来像:
@JvmSuppressWildcards
class CommandRouter @Inject constructor(
val outputter: Outputter,
val commands: Map<String, Command>
) {
// ...
}
推荐阅读
- mysql - 我想在满足类似条件的情况下按两个结果进行分组?
- python - 加载 ASGI 应用程序时出错。在模块“main”中找不到属性“app”
- java - 2 微服务如何维护会话和异常?
- angular - 使用 rxjs Observables 实现广度优先搜索
- java - 如果我想为 ArrayDeque 提供一个空值,我该怎么做
- typescript - 在 GraphQL Nexus.js 中定义类型时如何增加 ObjectDefinitionBlock?
- graphql - 对于模型 \"Proposal\" 的路径 \"_id\" 处的值 \"{ proposser: '618e49a68e18cd48286de4b5' }\" (type Object) 转换为 ObjectId 失败
- android - 将生命周期更新到版本 2.4.0 后生成错误 AAR 元数据文件:**/aar-metadata.properties
- python - AWS 的“凭证应限定在有效区域”的 alexa 顶级站点服务
- python-3.x - 暂停/延迟从 Swarm 发送新一批用户