Skip to content

Instantly share code, notes, and snippets.

@FredDeschenes
Created February 19, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FredDeschenes/83cee779fcc3fb1bb63c8fabfed28806 to your computer and use it in GitHub Desktop.
Save FredDeschenes/83cee779fcc3fb1bb63c8fabfed28806 to your computer and use it in GitHub Desktop.
Kotlin extension shadowing bug
import kotlin.reflect.KClass
fun main(args: Array<String>) {
UsesKClass.theFun(TestClass::class) //UsesKClass :: KClass
UsesTheAny.theFun(TestClass::class) //UsesTheAny :: Any
}
class TestClass
object UsesKClass {
fun theFun(klazz: KClass<*>) {
println("UsesKClass :: KClass")
}
fun theFun(klazz: Any) {
println("UsesKClass :: Any")
}
}
object UsesTheAny {
fun theFun(klazz: Any) {
println("UsesTheAny :: Any")
}
}
// Warning :: Extension is shadowed by a member: public final fun theFun(klazz: Any): Unit
fun UsesTheAny.theFun(klazz: KClass<*>) {
println("UsesTheAny :: KClass")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment