gpt4 book ai didi

kotlin - Dagger2和Kotlin:@Binds与@IntoMap不兼容

转载 作者:行者123 更新时间:2023-12-02 13:44:00 24 4
gpt4 key购买 nike

我正在从这里上课: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>
) {
// ...
}

关于kotlin - Dagger2和Kotlin:@Binds与@IntoMap不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60778218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com