0

我在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

4

1 回答 1

2
constructor(auth: FirebaseAuth, loginCallBack: (LoginAuthData) -> Unit)
constructor(auth: FirebaseAuth, registerCallBack: (RegisterAuthData) -> Unit)

JAVA两个构造函数都与is中的函数参数类型相同Lkotlin/jvm/functions/Function1

通过以下方式检查:

  1. Menu > Tools > Kotlin > Show Kotlin Bytecode
  2. 点击Decompile按钮
  3. 检查java代码

我的建议是尽可能使用默认参数而不是辅助构造函数:

class FirebaseUserAuth(private val auth: FirebaseAuth,
                       private val loginCallBack: ((LoginAuthData) -> Unit)? = null,
                       private val registerVM_CallBack: ((RegisterAuthData) -> Unit)? = null)
{
    ...
}
于 2019-10-19T02:56:49.117 回答