I’ve searched this channel for answer to this, and...
# multiplatform
a
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
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
Can this be applied to JS as well?
s
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.
a
Got it! Thanks!
👍 1