Luc Girardin
09/22/2020, 9:45 AMimport kotlin.jvm.JvmField
open class X(
@JvmField
open val x : Int = 0,
) {
fun getX() : Int = x
}
open class XY(
@JvmField
val y : Int = 0
) : X()
Trying to compile this little piece of code for the JVM will produce the following error:
Inherited platform declarations clash: The following declarations have the same JVM signature (getX()I):
fun <get-x>(): Int defined in XY
fun getX(): Int defined in XY
It seems that the @JvmField defined in X is not inherited by the XY class. From my perspective, this construct is valid and very useful if one want to keep compatibility with an API that offers both field and method-based access... even though this is usually bad yet common practice.
Thanks for listening!
LucLuc Girardin
09/22/2020, 9:46 AMTobias Berger
09/22/2020, 3:45 PMTobias Berger
09/22/2020, 3:58 PMTobias Berger
09/22/2020, 4:10 PMLuc Girardin
09/22/2020, 5:22 PMpublic class X {
public int x = 0;
public int getX() {
return x;
}
}
public class XY extends X {
public int y = 0;
}
Then only reason is not to break backward compatibility.Luc Girardin
09/22/2020, 5:23 PMnkiesel
09/23/2020, 1:05 AMx
and y
should be var
, no? Because in the Java code they are mutable.Luc Girardin
09/24/2020, 7:51 AM