Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin variable names: case sensitive?

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?

like image 968
hippo-dancer Avatar asked Mar 01 '23 10:03

hippo-dancer


1 Answers

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.

like image 104
Todd Avatar answered Apr 26 '23 02:04

Todd