From a function, can I easily resolve which functi...
# reflect
h
From a function, can I easily resolve which function that called it?
c
Copy code
Throwable().stackTrace[1].methodName
h
@christophsturm Thanks!
Any idea how expensive that is?
c
its not very expensive, but there is a newer api that you can use if you need the best performance: https://www.baeldung.com/java-9-stackwalking-api
as a rule of thumb i would use the not optimized version in test cases or in a test runner or assertion lib, but for production code i would use the stack walking
h
Good to know. Thanks!