https://kotlinlang.org logo
Title
v

vbsteven

05/15/2023, 6:39 PM
Is there any way in kotlin native to instantiate an object when all I have is a
KClass<*>
?
I'm trying to achieve a nice API to cast objects from one type to another using
val child = myParent.asType<MyChild>()
and currently it works through that
TypeCasting.castObject(obj, targetClass)
method that is implemented using a map of KClass objects to a factory function for each class in the library. But it looks like having that map of factory funtions has a huge impact on the time spent in
linkExecutable
tasks because (I presume) every class is potentially referenced in the output binary.