https://kotlinlang.org logo
#compiler
Title
# compiler
d

Dmitry Stakhov

11/15/2023, 10:38 AM
Is it ok this code is valid in Kotlin? Class Base doesn't explicitly tell that fun buz is overriden.
Copy code
interface MyInt {
    fun boo()
    fun buz()
}

open class Base {
    fun buz() {
        //
    }
}

class Impl: MyInt, Base() {
    override fun boo() {
        //
    }
}
😯 3
f

Foso

11/16/2023, 2:56 PM
Why should Base tell that? Base doesn't know about MyInt ?
d

Dmitry Stakhov

11/16/2023, 4:02 PM
Because in this case
Base
class implicitly overrides
fun buz
. There is no
override fun buz
in
class Imp
c

CLOVIS

11/17/2023, 1:17 PM
This case has come up previously on this slack, and I agree it's a bit weird. You can see it in action in the playground: https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS45LjIwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncy[…]B9XG59XG5cbmZ1biBtYWluKCkge1xuICAgIEltcGwoKS5idXooKVxufSJ9
w

wasyl

11/17/2023, 1:21 PM
Do you recall how it's explained, or do you have a link/hint how to search for it? It's definitely surprising and I'd love to know more details
c

CLOVIS

11/17/2023, 1:23 PM
It was a long time ago, so I don't think it will show up in this slack's history… I don't remember if there was any explanation, other than people being surprised. If you really want to learn more about it, I think it's worth creating an issue (https://kotl.in/issue) to ask the team directly
👍 1