Hi, Yesterday I discovered that kotlin allows this...
# announcements
u
Hi, Yesterday I discovered that kotlin allows this sort of code:
Copy code
data class Thing (
    val prop: String
) {

  private fun getProp(): Int = 5
}
Although this code won’t compile:
Copy code
data class Thing (
    val prop: String
) {

  private fun getProp(): String = "a"
}
with error “Platform declaration clash: The following declarations have the same JVM signature (getProp()Ljava/lang/String;)” The first one compiles successfully, and the
getProp
function can be either
private
or
public
. In Java, the same code won’t compile:
Copy code
public class Test {

  private String prop;

  public final String getProp() {
    return prop;
  }

  public void setProp(String prop) {
    this.prop = prop;
  }

  private final int getProp(){
    return 5;
  }
}
With error: “‘getProp()’ is already defined in ‘com.ni.monday.model.domain.webhooks.events.Test’” So why is it allowed in Kotlin? The consequences of this is this bug, I opened yesterday on #jackson-kotlin : https://github.com/FasterXML/jackson-module-kotlin/issues/341
p
There are no fields in Kotlin (just backing fields) and getters/setters are part of property. Don’t introduce Kotlin Beans 🙂
🙂 1
☝️ 2
😂 1