Skip to content

Instantly share code, notes, and snippets.

@hanslovsky
Created March 30, 2022 20:10
Show Gist options
  • Save hanslovsky/42530ab479b2272e94498ab47e28b460 to your computer and use it in GitHub Desktop.
Save hanslovsky/42530ab479b2272e94498ab47e28b460 to your computer and use it in GitHub Desktop.
Exploring how kotlin extension functions are resolved
interface Base<T: Base<T>>
interface Derived<T: Derived<T>> : Base<T>
class Impl: Derived<Impl>
data class Container<T>(val t: T)
@JvmName("f1")
fun <T: Base<T>> Container<T>.someFunc(c: Container<T>) =
println("generic: $c")
@JvmName("f2")
fun Container<out Derived<*>>.someFunc(c: Container<out Derived<*>>) =
println("star projection: $c")
@JvmName("g1")
fun <T: Derived<T>> Container<T>.someOtherFunc(c: Container<T>) =
println("generic: $c")
@JvmName("g2")
fun Container<out Derived<*>>.someOtherFunc(c: Container<out Derived<*>>) =
println("star projection: $c")
fun main() {
val c = Container(Impl())
c.someFunc(c)
c.someOtherFunc(c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment