private class FakeCardDrawable constructor(
context: Context) : CardDrawable(context) {
var text: String? = null
var backgroundColor = 0
var textColor = 0
override fun setColors(
backgroundColor: Int, textColor: Int, animate: Boolean
) {
this.backgroundColor = backgroundColor
this.textColor = textColor
}
fun setText(text: String) {
this.text = text
}
}
它抱怨说"平台声明冲突:以下声明具有相同的JVM签名(setText..(
因为您的var text
和函数setText()
都被翻译到JVM中的一个名为setText()
的公共方法。
为了避免平台声明冲突,您在这里有3个选项:
- 更改
var text
的名称或setText
的名称 - 使用专用
set
制作var text
:
var text: String? = null
private set
- 更改方法的JVM名称:
@JvmName("myJvmName")
fun setText(text: String) {
this.text = text
}