Is there a way to instantiate an object of a certa...
# kotlin-native
s
Is there a way to instantiate an object of a certain class using reflection in K/N? Sadly looks like
KClass.constructors
is only available in JVM/JS
s
Reflection isn’t supported in native.
s
It has limited reflection support at least (callable references). Trying to see if there’s any way to do class instantiation though, seems like that may not be possible in K/N yet (if ever)
o
If set of classes is limited, you could have simple
when
clause over all classes you want to instantiate.
s
The set of classes is unfortunately not known as they are defined by consumers of the SDK I am writing (basically I define a class that consumers make as many classes as they want that inherit it, and I want to use reflection to instantiate objects of all such classes)
s
Can you have the consumers register a factory for the class? It could be as simple as a lambda function passed into a method.