Suppose I have a kotlin interface with `var backgr...
# getting-started
m
Suppose I have a kotlin interface with
var background: Drawable
and I want to create a Kotlin class implementing this interface and extending a java class that already defines
setBackground(Drawable)
and
Drawable getBackground()
. In Java, I don't need to do anything because the new subclass automatically implements these interface methods. In Kotlin, I get a compile error that the new subclass does not implement those interface methods. How to achieve this?
d
Unfortunately right now you will not be able to both extend the Java class and directly implement the interface from Kotlin.
👍 1
As a work-around, you could move the interface to Java, maybe.
But I have not tried that.
m
Thanks, I'm also looking at this: https://stackoverflow.com/a/44035461/444761
d
You could maybe use
@JvmName
on the interface, but I am not sure if that works.
m
For the moment, I'll just refactor the interface vars to getDrawable/setDrawable funs
I think that works...
d
It should, but you loose the nice property syntax.