interface MyInterface {
fun getTheString(): String
}
class MyClass(var theString: String) : MyInterface {
...
}
normally when I have a variable in the constructor for a class, it creates a getter and setter for that variable. In MyClass
, the methods getTheString()
and setTheString(String)
exist when not implementing MyInterface
.
When MyClass
implements MyInterface
, I get the error:
Accidental override: The following declarations have the same JVM signature (getTheString()Ljava/lang/String;):
- public final fun (): String defined in MyClass
- public abstract fun getTheString(): String defined in MyClass
I also have the error: Class 'MyClass' is not abstract and does not implement abstract member public abstract fun getTheString(): String defined in MyInterface.
So I have a few questions:
- Why are 2 getter methods getting generated with the same JVM signature when implementing the interface versus one getter method getting generated without implementing the interface?
- Why is it complaining I haven't implemented a
getTheString()
method when this method is automatically generated by kotlin? - How can I get the getter generated by the variable to become the implementation of the method in the interface?
@get:JvmName("getTheString_")
? – EpicPandaForcevar theString
, but does not use the method generated by the variable as the implementation of the method within the interface – backcab