PHondogo
08/28/2023, 11:37 AMinterface A {
fun x() : Int
}
interface B : A {
override fun x(): Int = 1
}
open class C: A {
final override fun x(): Int = 2
}
class D: C(), B // Error : Class 'D' must override public final fun x(): Int defined in C because it inherits many implementations of it
Why D not prefer C::x over B::x?
B::x is the interface's default function that must be applied only if there is no implementation of that method in class (even class having implementation is super).
I checked such case in Java - there is no such issue there, Java compiler is choosing C::x.dmitriy.novozhilov
08/28/2023, 11:41 AMWhyI can ask why not opposite? In Kotlin the semantic difference between classes and interfaces is quite minimal, so it's not fair to choose between those functions only based on class kinds ofnot preferD
overC::x
?B::x
B
and C
Tóth István Zoltán
08/28/2023, 11:43 AMPHondogo
08/28/2023, 11:43 AMdmitriy.novozhilov
08/28/2023, 11:45 AM