kotlin限定符注释被忽略
下面的代码编译第一次,但在第二次构建给出:
错误:SomeObject绑定多次:
@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
- Kotlin和Dagger:我可以使用@Inject的对象仍然可以为空/可选?
- Kotlin:Dagger2 @Inject context var始终为空
- 如何在Kotlin中使用Dagger的2 @Named限定符
- 为什么在编译时使用kotlin在Dagger2中使用Scopes和Singleton注释会导致错误?
- 如何在Kotlin中注入var?
请尝试删除这一行@Retention(AnnotationRetention.SOURCE)
。 就我所知,Dagger 2需要RUNTIME
保留(这是Kotlin中的默认保留,因此不需要明确指定)。
- Dagger不会为androidTest生成组件
- 在Dagger 2中提供方法
- Kotlin Kapt:java.lang.IllegalStateException:endPosTable已经设置
- 从Activity 中调用Fragments演示者的方法
- Retrofit2 + Kotlin中的SimpleXML:MethodException:注释必须标记一个set或get方法
- 匕首2不识别Kotlin的提供方法。 Java工作正常
- Android Studio无法重构“只读”kapt生成的代码
- 用匕首使用Kotlin
- 如果没有kotlin中的@ Provide-或@ Produces注解方法,则不能提供上下文