It would be great if we can get the fully qualifie...
# stdlib
m
It would be great if we can get the fully qualified name of a class inlined at compile-time. That would allow us to register available classes and check for their existence in other modules in a multiplatform-compatible way without using reflection API. Like
Copy code
// base module provides registry
interface Feature

private val availableFeatureTypes = hashSetOf<String>()

inline fun <reified TFeature: Feature> registerFeature(feature: TFeature) {
    availableFeatureTypes.add(typeNameOf<TFeature>())
    // …
}
inline fun <reified TFeature: Feature> isFeatureAvailable() =
    availableFeatureTypes.contains(typeNameOf<TFeature>()) // no 'NoClassDefFoundError' because inlined


// a module providing `SomeFeature` registers it by fully qualified name
object SomeFeature: Feature

fun someFunThatGetsCalledIfModuleIsUsed() {
   registerFeature(SomeFeature)
}


// another module can optionally depend on SomeFeature
if (isFeatureAvailable<SomeFeature>()) { // no 'NoClassDefFoundError' because inlined
    val feature = SomeFeature() // executed only if SomeFeature is available
    // …
}
World that approach work in Kotlin Native or would it fail because everything is resolved at compile-time even if the code is never executed?