Dagger-reflect: class 定义多个@Inject-annotations 构造函数
Dagger-reflect: class defines multiple @Inject-annotations constructors
我尝试在我的应用程序中使用 dagger-reflect 来提高应用程序调试版本的构建速度。
不幸的是,我的应用程序在运行时崩溃并显示堆栈跟踪并出现以下错误:
java.lang.IllegalStateException: com.example.MyClass defines multiple
@Inject-annotations constructors
用 kotlin 编写的 MyClass 如下所示:
class MyClass @Inject constructor(@HostQualifier host: String = "")
并且我使用这样的 dagger 模块来提供主机:
@Module
object SampleModule {
@Provides
@JvmStatic
@HostQualifier
fun provideHost(): String = "Example"
}
问题在于在注入的构造函数中使用 kotlin 的默认值。
这样的代码:
class MyClass @Inject constructor(@HostQualifier host: String = "")
使用 @Inject
注释生成第二个构造函数。
这就是它导致异常的原因:
MyClass defines multiple @Inject-annotations constructors
解决方案只是从构造函数中删除默认值:
class MyClass @Inject constructor(@HostQualifier host: String)
我尝试在我的应用程序中使用 dagger-reflect 来提高应用程序调试版本的构建速度。
不幸的是,我的应用程序在运行时崩溃并显示堆栈跟踪并出现以下错误:
java.lang.IllegalStateException: com.example.MyClass defines multiple
@Inject-annotations constructors
用 kotlin 编写的 MyClass 如下所示:
class MyClass @Inject constructor(@HostQualifier host: String = "")
并且我使用这样的 dagger 模块来提供主机:
@Module
object SampleModule {
@Provides
@JvmStatic
@HostQualifier
fun provideHost(): String = "Example"
}
问题在于在注入的构造函数中使用 kotlin 的默认值。
这样的代码:
class MyClass @Inject constructor(@HostQualifier host: String = "")
使用 @Inject
注释生成第二个构造函数。
这就是它导致异常的原因:
MyClass defines multiple @Inject-annotations constructors
解决方案只是从构造函数中删除默认值:
class MyClass @Inject constructor(@HostQualifier host: String)