Finding a singleton via reflection

I want to find all object derived from a certain class (Config), what is easy to do with the Reflections library:

interface Config {
  val name: String
}

object MyConfig : Config {
  override val name = "demo"
}

val reflections = Reflections("org.demo")
val configClass = reflections.getSubTypesOf(Config::class.java).first()

I get the class as expected. But how do I get the singleton object MyConfig for this class? I don’t want to create a new instance, but get the existing one.

You do this using the objectInstance property: objectInstance - Kotlin Programming Language

Thanks. And how do I get a KClass instance in this case? “reflections” returns Classes.

You can use .kotlin to get a KClass for any Java class.

Thank you!