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 125 views
1 answer 121 views
121 views asked Feb 4, 2024 by avibootz
1 answer 135 views
1 answer 110 views
1 answer 118 views
...