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

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);
}
}
上一篇:MySQL----数据库简单操作


下一篇:git diff patch方法