Reputation: 351
I used example in https://google.github.io/dagger/multibindings
Module A
@Module
object MyModuleA {
@Provides
@IntoSet
fun provideOneString(): String {
return "ABC"
}
}
Module B
@Module
object MyModuleB {
@Provides
@ElementsIntoSet
fun provideSomeStrings(): Set<String> {
return HashSet<String>(Arrays.asList("DEF", "GHI"))
}
}
component
@Component(modules = [ MyModuleA::class, MyModuleB::class])
interface MyComponent {
fun strings(): Set<String>
}
test
@Test
fun testMyComponent() {
val myComponent = DaggerMyComponent.builder().build()
println("${myComponent.strings()}")
}
It show error with MyModuleA must be set, but changing module from object to class is work fine.
@Module
class MyModuleA {
@Provides
@IntoSet
fun provideOneString(): String {
return "ABC"
}
}
@Module
class MyModuleB {
@Provides
@ElementsIntoSet
fun provideSomeStrings(): Set<String> {
return HashSet<String>(Arrays.asList("DEF", "GHI"))
}
}
@IntoSet annotation is not work in kotlin object?
Upvotes: 1
Views: 3598
Reputation: 420
I ran into the same problem and this answer solved it for me.
Dagger 2 multibindings with Kotlin
In short, you need to use Set<@JvmSuppressWildcards String> intead, because of the way that kotlin handles type variance in generics.
Upvotes: 10