Created
March 30, 2022 20:10
-
-
Save hanslovsky/42530ab479b2272e94498ab47e28b460 to your computer and use it in GitHub Desktop.
Exploring how kotlin extension functions are resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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