I have a third party java library with a class like
public class ThirdParty {
public String getX() {
return null;
}
}
I also have an interface in kotlin like
interface XProvider {
val x: String?
}
Now I want to extend the ThirdParty
class and implement the XProvider
interface. This has been working fine in my legacy java code:
public class JavaChild extends ThirdParty implements XProvider {}
However, I would like to write as much kotlin as possible and am trying to convert my java classes to kotlin. Sadly, the following does not work:
class KotlinChild: ThirdParty(), XProvider
Error is
class 'KotlinChild1' must be declared abstract or implement abstract member public abstract val x: String? defined in XProvider
However, if I do something like
class KotlinChild1: ThirdParty(), XProvider {
override val x: String? = null
}
I get
error: accidental override: The following declarations have the same JVM signature (getX()Ljava/lang/String;)
fun <get-x>(): String?
fun getX(): String!
override val x: String? = null
What works is the following ugly work-around:
class KotlinChild: JavaChild()