A function is easy to call if it is a member of a class:
package com.example
class MyClass {
fun myFunction() : String {
return "result"
}
}
val myClass = Class.forName("com.example::MyClass").kotlin
val myFunction = myClass.functions.firstOrNull { it.name == "myFunction" }
val result = myFunction?.call()
But what if the function is without a class?
package com.example
fun myFunction() : String {
return "result"
}
Condition: file name unknown.
In JVM there will still be a class, it is the file name with the Kt suffix.
1
Can you give us a video because it is easier to understand from there?
Sun Flower is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Can you give demo video as well. Its easily to see how this code working. if you want certification exam related guide contact at dumpsexpert.com
Exams Buzz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.