I've got a Java interface
public interface SampleInterface extends Serializable {
Long getId();
void setId(Long id);
}
and a Kotlin class that is supposed to implement it
open class ClazzImpl() : SampleInterface
private val id: Unit? = null
fun getId(): Long? {
return null
}
fun setId(id: Long?) {
}
However I get a compilation error:
Class ClazzImpl is not abstract and does not implement abstract member public abstract fun setId(id: Long!): Unit defined in com....SampleInterface
any ideas what is wrong?
The other answers from Egor and tynn are important, but the error you have mentioned in the question is not related to their answers.
You have to add curly braces first.
open class ClazzImpl() : SampleInterface {
private val id: Unit? = null
fun getId(): Long? {
return null
}
fun setId(id: Long?) {
}
}
If you add the curly braces, that error would have gone but you will get a new error like this:
'getId' hides member of supertype 'SampleInterface' and needs 'override' modifier
Now, as suggested in the other answers, you have to add override modifier to the functions:
open class ClazzImpl() : SampleInterface {
private val id: Unit? = null
override fun getId(): Long? {
return null
}
override fun setId(id: Long?) {
}
}
You have to add the override
keyword before fun
:
override fun getId(): Long? {
return null
}
override fun setId(id: Long?) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With