Why is it extension functions are always shadowed ...
# announcements
h
Why is it extension functions are always shadowed by class functions? It would be really useful to be able to override them in narrow scopes
c
On JVM level extension function is defined as a static "utility" function. e.g.
Copy code
class Something {}
fun Something.extFunction() {}
Function
extFunction
will be generated as something like this:
Copy code
class SomeClassKt {
    public static extFunction(Something $receiver) {}
}
The only way to reliably override member with an extension would be modifying the class of the reciever - either as a pre-compilation patch on the source file or byte code modification.
k
Copy code
iterface Animal {
    fun foo() = "foo"
}
class Dog: Animal

fun Dog.foo() = "bar"

val dog = Dog()
val animal = dog

dog.foo() == "bar"
animal.foo() == "foo"
Behaviour like this would be very unintuitive.
h
hence why you would use them in really narrow scopes, right?