According to this article (<https://android.jlelse...
# announcements
j
According to this article (https://android.jlelse.eu/the-ugly-truth-about-extension-functions-in-kotlin-486ec49824f4), if an extension method and member method have the same signature, the member method will always win. But what about if a subtype has a member method with the same signature as the extension method? It seems the latter wins this time, but is any way to make the member method used instead (I’m trying to work around some extension methods in unit tests).
c
Extension functions are resolved statically, so it's what you declare as type you're calling the extension on, not what's there in runtime.
Copy code
open class A
class B : A() {
	fun test() { println("child member") }
}

fun A.test() { println("extension") }

val v: A = B()
v.test()
//result:
extension
Because
v
is declared as
A
, even though at runtime it is actually B, the
test
function was resolved at compile time statically to the extension fun.
j
Okay, I think that makes sense. Fortunately, I have found a simpler way to do what I need (I guess I just needed to try the complicated way a few times before it would dawn on me). Thanks!
c
Cheers 🙂