Kotlin 匕首2&;科特林:@Binds';不能使用@IntoMap
我在这里上一课: 当我更改代码时Kotlin 匕首2&;科特林:@Binds';不能使用@IntoMap,kotlin,dependency-injection,dagger-2,dagger,Kotlin,Dependency Injection,Dagger 2,Dagger,我在这里上一课: 当我更改代码时 @Module abstract class HelloWorldModule { @Binds abstract fun helloWorldCommand(command: HelloWorldCommand): Command } 进入 我得到一个错误: error: [Dagger/MissingBinding] Map<String,? extends Command> cannot be provided withou
@Module
abstract class HelloWorldModule {
@Binds
abstract fun helloWorldCommand(command: HelloWorldCommand): Command
}
进入
我得到一个错误:
error: [Dagger/MissingBinding] Map<String,? extends Command>
cannot be provided without an @Provides-annotated method.
错误:[匕首/缺失绑定]映射
如果没有@Providers注释的方法,则无法提供。
我错过了什么?它对Kotlin不起作用?谢谢
@David Medenjak
,你说得对!
上面的代码没有问题,问题是缺少@jvmsuppresswidcards
,因此我的类CommandRouter
现在看起来像:
@JvmSuppressWildcards
class CommandRouter @Inject constructor(
val outputter: Outputter,
val commands: Map<String, Command>
) {
// ...
}
@JvmSuppressWildcards
类CommandRouter@Inject构造函数(
val输出器:输出器,
val命令:映射
) {
// ...
}
谢谢@David Medenjak
,你说得对!
上面的代码没有问题,问题是缺少@jvmsuppresswidcards
,因此我的类CommandRouter
现在看起来像:
@JvmSuppressWildcards
class CommandRouter @Inject constructor(
val outputter: Outputter,
val commands: Map<String, Command>
) {
// ...
}
@JvmSuppressWildcards
类CommandRouter@Inject构造函数(
val输出器:输出器,
val命令:映射
) {
// ...
}
可能取决于您使用的匕首版本可能取决于您使用的匕首版本