I just call a method class through this line :
val instance = Class.forName(nameClass).kotlin.objectInstance
When I set the nameClass with a constant value (see below) it's work.
private const val PROVIDER_CLASS = "com.abc.xyz.feature.DynamicFeatureImpl\$Provider"
fun method() {
val instance = Class.forName(PROVIDER_CLASS).kotlin.objectInstance
}
But, when I set the nameClass to string (not constant), like this
fun method() {
val nameClass = "com.abc.xyz.feature.DynamicFeatureImpl\$Provider"
val instance = Class.forName(nameClass).kotlin.objectInstance
}
it's not work and throw java.lang.ClassNotFoundException.
I have trying make log, check is the value PROVIDER_CLASS are same with the string nameClass, and the result is true. but the code not work with string one. My goal is make the code work through variable className string as parameter.
So, what wrong with the code? it's make me confused.
Update: Actually it's call a method from dynamic feature with dagger. my reference this medium post