Kotlin language spec claims identifiers are case-sensitive yet the following produces compiler error messages because of apparently case-insensitive generated getters/setters.
var a=10; var A=20
Clash.kt:1:1: error: platform declaration clash: The following declarations have the same JVM signature (getA()I):
fun <get-A>(): Int defined in root package
fun <get-a>(): Int defined in root package
var a=10
^
I understand what is happening but does this seem like the right behavior? Is there a way around this?
CodePudding user response:
This has to do with how the compiler creates getters and setters to match the Java Beans standard. In this case, both of the getters and setters are named getA()
and setA(...)
because it tries to use the initial caps version of the field. If these fields were named aa
and AA
, however, you'd have getAa()
and getAA()
and wouldn't have a name collision.
CodePudding user response:
An alternative workaround is to use @JvmField
on one or both of the properties. This prevents Java getter and setter methods from being generated, so there are no clashing method signatures to worry about.