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 113 views
1 answer 105 views
105 views asked Feb 4, 2024 by avibootz
1 answer 125 views
1 answer 90 views
1 answer 104 views
...