I’ve searched this channel for answer to this, and found nothing (perhaps I’m doing it wrong :-) ), but is there a way to do the following using KClass...
Class.forName(...).newInstance()
s
Sam
12/11/2020, 3:24 PM
You wouldn’t be able to do it in common code. If your platform is jvm or android you can use normal reflection to create a new instance. Reflection on native is too limited to do that. You’ll need a different way. DI frameworks like Koin let you associate closures that are in charge of creating a new instance with a class. You could do something like that.
a
Alfred Lopez
12/11/2020, 3:28 PM
Can this be applied to JS as well?
s
Sam
12/11/2020, 3:38 PM
Associating factory closures with a class? Yes, I don’t see why not. I know almost nothing about Kotlin/JS though. I only use Kotlin on Android and iOS.