0
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
    }
}

It complains saying "Platform declaration clash: The following declarations have the same JVM signature(setText..)

Artur A
  • 257
  • 3
  • 20

1 Answers1

1

Because your var text and your function setText() are both translated into JVM to a public method named setText().

To avoid platform declaration clash you have 3 options here:

  1. Change the name of var text or the name of setText
  2. Make var text with a private set:
var text: String? = null
  private set
  1. Change the JVM name of the method:
@JvmName("myJvmName")
fun setText(text: String) {
    this.text = text
}
Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70