Uziel Sulkies
05/21/2020, 6:25 AMdata class Thing (
val prop: String
) {
private fun getProp(): Int = 5
}
Although this code won’t compile:
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:
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 #C0BLHCSHZ : https://github.com/FasterXML/jackson-module-kotlin/issues/341pawegio
05/21/2020, 8:47 AM