In kotlin KClass is sub class of Any… But how can I tell that I want the Object and not KClass?
For example…
public fun <T: Any> test(kclass: KClass<T>, obj: T){
println("Hello from KClass<T>, T")
}
Clearly… we can see that function accepts class reference and object… Wrong!!!
Nothing stops you to call it like this…
test(String::class, String::class)
Ps: I’m writing library where I have overloading functions objects/classes and I need distinctions between KClass and Object class, I really really really don’t want to name the function with different names because it will burden the user with to much
names to remember…
Test you Kotlin knowledge: What will be printed on console???
fun <T: Any> test(kclass: KClass<T>, obj: T){
println("Hello from KClass<T>, T")
}
fun <T: Any> test(obj0: T, obj1: T){
println("Hello from T, T")
}
public fun main() {
test(String::class, String::class)
test("asdf", "asdf")
test(String::class, "asdf")
test("asdf", String::class)
}