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
Sam
01/16/2020, 5:44 PM
Reflection isn’t supported in native.
s
Sam Schilling
01/16/2020, 6:02 PM
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
olonho
01/17/2020, 1:37 AM
If set of classes is limited, you could have simple
when
clause over all classes you want to instantiate.
s
Sam Schilling
01/17/2020, 4:44 PM
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
Sam
01/17/2020, 7:13 PM
Can you have the consumers register a factory for the class? It could be as simple as a lambda function passed into a method.