Hi,
Is there a way to find out the name of the current function being run? Something like:
fun someFunc() {
val currentFuncName = getCurrentFuncName() // how to implement this?
if (currentFuncName == "someFunc") println("Great! We are in someFunc!")
}
Thanks
Depends on target platform. In jdk you can use:
- …javaClass.enclosingMethod.name for any object instance produced in your method (function)
- Throwable().stackTrace contains it on top
- Thread.currentThread().stackTrace contains it
Something similar always presents on other platforms, anyway you have stacktrace even in js.
2 Likes