I'm building a library and I want the library to be able to distinguish the different times when the user in his code calls the functions in my library. For example, if I have a function sayHello()
defined like so:
fun sayHello() {
when(idOfFunctionCall) {
0 -> println("First call!")
1 -> println("Second call!")
else -> println("Some other call!")
}
}
I want this function to be able to detect the different places in the user's code where this function was called.
// user's code
fun main() {
sayHello()
repeat(3) {
sayHello()
}
sayHello()
}
This code should print:
First call!
Second call!
Second call!
Second call!
Some other call!
Is that even possible? I'm planning on using the Kotlin Reflection set of tools but I'm not sure if it is possible.
Aucun commentaire:
Enregistrer un commentaire