I am writing a class implementing an interface that exposes a setSelected
method. This class will have a selected
property:
private class Foo : IFoo {
var selected = false
override fun setSelected(isActive: Boolean) {
selected = isActive
}
}
However the compiler complains, as Kotlin generates a setter for selected
, that the two methods clash:
Error:(14, 9) Kotlin: [com.bar.jvmTest] Platform declaration clash: The following declarations have the same JVM signature (setSelected(Z)V):
fun <set-selected>(<set-?>: Boolean): Unit defined in foo.bar.baz.Foo
fun setSelected(isActive: Boolean): Unit defined in foo.bar.baz.Foo
Error:(24, 9) Kotlin: [com.bar.jvmTest] Platform declaration clash: The following declarations have the same JVM signature (setSelected(Z)V):
fun <set-selected>(<set-?>: Boolean): Unit defined in foo.bar.baz.Foo
fun setSelected(isActive: Boolean): Unit defined in foo.bar.baz.Foo
override
and so my class does not fully implement the interface:
Error:(11, 13) Kotlin: [com.bar.jvmTest] Class 'Foo' is not abstract and does not implement abstract member public abstract fun setSelected(isActive: Boolean): Unit defined in bar.baz
selected
to e.g. dataSelected
so that the generated setter doesn't clash with the method, but there should be a way to keep this simple property name and implement the interface as expected.