what if said function is an extension? e.g. `fun O...
# getting-started
p
what if said function is an extension? e.g.
fun OtherType.myFunc(...)
, what's the syntax to choose the right super extension function for my override?
d
(obj as OtherType).extensionFunction()
Note however that extension functions are always statically resolved. There is no overriding them.
m
@diesieben07 You can actually override an extension function if it's defined inside a class 🙂
Copy code
open class A {
    open fun String.makeInt(): Int = toInt()
}

class B : A() {
    override fun String.makeInt(): Int = toInt() + 1
}
d
Yes, that is true. However there is no polymorphism on the extension-receiver type, which is what I was trying to say
p
the issue is that I'm bringing into scope 2 overridden versions of the same extension method by delegating 2 different classes that have overlapping mthod
and I wanted to remove the ambiguity by choosing one of the delegated overrides explicitly
d
Overriding is the wrong word here. Extension methods can hide each other, but not override.
Or do you really have the situation that was given by Marius above
p
one of the delegate extension was hiding the other, and IDEA suggested to override explicitly the extension in my class. Though I didn't want to define the code myself but borrow one of the delegators implementation using the
super
syntax if possible
e
I tried different solutions (like scoping the object to have access to the extension) But nothing seems to work. The restrictions on `super`: Cannot be the target of a extension function and cannot be used as an expression forbids all the workarounds I can think of.
d
Like I said, extension functions are resolved statically, so a cast to a static type is needed.