Yesterday I was asked this question on stackoverflow but no one answered. The question is:
Why this code:
open class Base { open fun sayHello(){ println("Hello, I'm base") } }
trait Trait: Base {
override fun sayHello() {
println(“Hello, I’m trait”)
}
}class Derived(): Base(), Trait
fun main(args: Array<String>) {
Derived().sayHello()
}
prints
Hello, I'm base
Moreover, if I override "fun sayHello" in "Derived" by hand:
class Derived(): Base(), Trait {
override fun sayHello() {
super<Trait>.sayHello()
}
}
it again prints
Hello, I'm base
What is wrong?
Of course I’m excepting that ouput is:
Hello, I’m trait
In both cases
Kotlin Compiler version 0.5.295