In Java you are able to write plugins for your application with ServiceLoader.
In this case you can define:
interface A
and class B implements A
and simply in your code do the following:
- Create an external plugin with a configuration, where you will define, that your class B is implementing this interface;
- Load the proper implementation of a plugin, that will be taken from a configuration with
ServiceLoader.load(A::class.java)
; - Work with implementation B of interface A;
But what to do when I try to load external plugin on the runtime of a Kotlin native application?
Is there any libraries or any chance to inject external code in the same way as it is done with ServiceLoader on the runtime?