java代码获知该方法被哪个类、哪个方法、在哪一行调用

来源:互联网 发布:淘宝网腿祙裤 编辑:程序博客网 时间:2024/04/29 03:48
public class TestMain {    public static void  main(String[] args){        hello();    }        public static void hello() {        String className = Thread.currentThread().getStackTrace()[2].getClassName();        String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();        int lineNumber = Thread.currentThread().getStackTrace()[2].getLineNumber();                System.out.println(className);        System.out.println(methodName);        System.out.println(lineNumber);    }}

0 0