1
下面
代碼編譯的第一次,但未能在第二次構建,並提供:科特林預選賽annotaion被忽略
Error:SomeObject is bound multiple times:
@Provides @NotNull SomeObject SomeModule.provideSomeObject()
@Provides @NotNull SomeObject SomeModule.provideSomeScopedObject()
看來,編譯器會忽略Qualifier
說明在連續的基礎之上。
當在java中編寫組件和模塊時,它不起作用,因爲Main
類中的註釋被忽略。
@dagger.Component(modules = arrayOf(SomeModule::class))
interface Component {
fun inject(main: Main)
}
class Main {
@field:[javax.inject.Inject SomeScope] lateinit var obj: SomeObject
}
@dagger.Module
class SomeModule {
@dagger.Provides
fun provideSomeObject(): SomeObject {
return SomeObject("noScope")
}
@SomeScope
@dagger.Provides
fun provideSomeScopedObject(): SomeObject {
return SomeObject("someScope")
}
}
data class SomeObject(val name: String)
@javax.inject.Qualifier
@Retention(AnnotationRetention.SOURCE)
annotation class SomeScope
謝謝,現在的問題是爲什麼'SOURCE' retension在java上工作得很好 – Sigitas