- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
@Named 如何与 @BindsInstance 一起使用?我有这个组件
interface AppComponent : AndroidInjector<MyApplication>{
@Component.Builder
abstract class Builder : AndroidInjector.Builder<MyApplication>() {
@BindsInstance
abstract fun preferenceName( @Named("PreferenceName") name : String ) : Builder
}
}
@Inject
@Named("PreferenceName")
lateinit var prefName : String
最佳答案
更新: Dagger 2.25.2消除了对解决方法的需要:
Kotlin support
ii. Qualifier annotations on fields can now be understood without The need for @field:MyQualifier (646e033)
iii. @Module object classes no longer need @JvmStatic on the provides methods. (0da2180)
@BindsInstance
没有任何关系,而是
@Named
字段上的注释。您可以从“MissingBinding for String”中看出,否则会给您一个有关命名字符串的错误。
@field:[Inject Named("PreferenceName")]
lateinit var prefName : String;
The reason is because in Kotlin annotations need to be slightly more complicated in order to work as expected from Java perspective. That’s coming from the fact that one Kotlin element may be a facade of multiple Java elements emitted in the bytecode. For example a Kotlin property is a facade of an underlying Java member variable, a getter and a setter. You annotate the property but what Dagger expects to be annotated is the underlying field.
关于kotlin - Dagger2 - 如何使用 @Named 和 @BindsInstance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54115182/
我最近将 dagger 2.8 更新为 2.9 dagger。和最新版本的文档已添加如下: -添加@BindsInstance组件构建器可以轻松绑定(bind)在图之外构建的实例。 -制作人:已添加
@Named 如何与 @BindsInstance 一起使用?我有这个组件 interface AppComponent : AndroidInjector{ @Component.Build
请帮帮我!我在使用 dagger 2 时遇到了麻烦。 我想通过使用 @Subcomponent.Builder 和 @BindsInstance 在 MainActivity 中绑定(bind)一些运
我是一名优秀的程序员,十分优秀!