我在FirebaseUserAuth
类中有两个构造函数,并且给出错误:声明具有相同的Java签名。构造函数的参数不同。为什么会出现相同的签名错误?该如何解决?。
class FirebaseUserAuth(private val auth: FirebaseAuth,
private val loginCallBack: ((LoginAuthData) -> Unit)?,
private val registerVM_CallBack: ((RegisterAuthData) -> Unit)?)
{
constructor(auth: FirebaseAuth, loginCallBack: (LoginAuthData) -> Unit): this(auth, loginCallBack, null)
constructor(auth: FirebaseAuth, registerCallBack: (RegisterAuthData) -> Unit): this(auth, null, registerCallBack)
}
错误
> Platform declaration clash:The following declarations have the same JVM
> signature (Lcom/google/fireBase/auth/FirebaseAuth;Lkotlin/jvm/
> functions/Function1;)V):
>
> • public constructor FirebaseUserAuth(auth: FirebaseAuth,
> loginCallBack: (LoginAuthData) -> Unit) defined.
> com.examgle.data.FirebaseUserAuth
>
> • public constructor FirebaseUserAuth(auth: FirebaseAuth,
> registerCallBack: (RegisterAuthData) -> Unit) defined.
> com.examgle.data.FirebaseUserAuth
constructor(auth: FirebaseAuth, loginCallBack: (LoginAuthData) -> Unit)
constructor(auth: FirebaseAuth, registerCallBack: (RegisterAuthData) -> Unit)
两个构造函数都与JAVA
中的函数参数的类型为Lkotlin/jvm/functions/Function1
相同。
通过以下方式进行检查:
Menu > Tools > Kotlin > Show Kotlin Bytecode
Decompile
按钮我的建议是,如果可能,使用default参数而不是辅助构造函数:
class FirebaseUserAuth(private val auth: FirebaseAuth,
private val loginCallBack: ((LoginAuthData) -> Unit)? = null,
private val registerVM_CallBack: ((RegisterAuthData) -> Unit)? = null)
{
...
}