How to get the name of the method that called the current method in Java

1 Answer

0 votes
public class MyClass {
    public static void test() {
        System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
    }
    
    public static void main(String args[]) {
        test();
    }
}
        
        
        
        
/*
run:
        
main

*/

 



answered Oct 7, 2023 by avibootz

Related questions

1 answer 129 views
1 answer 124 views
124 views asked Feb 4, 2024 by avibootz
1 answer 138 views
1 answer 114 views
1 answer 119 views
...