So... I thought I knew how interfaces worked... bu...
# getting-started
c
So... I thought I knew how interfaces worked... but to my surprise something unexpected is happening. I'm able to compile my code with a new method defined in my interface and I didn't have to override it... can anyone explain?
Copy code
interface MyScreen {
    fun onClickOfSomething(path: String) {}
What's up with that?
c
the
{}
provides an empty, default implementation of your function.
c
oh crap. interfaces can have defaults now?
c
been that way for quite a while, in both Kotlin and Java.
e
since Java 8 and before Kotlin 1.0, IIRC
although since Kotlin originally targeted Java 6, the way it works is not entirely compatible (e.g. a Kotlin interface with default implementations may not be easily implemented in Java under some circumstances)
it should "just work" with current versions unless you're doing something unusual, though
c
interesting. i somehow completely eluded that language feature. TIL. thanks for teaching
a
Ohhh nice to know that .. thanks!