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); } }
E-mail: huahuiyang@gmail.com
https://www.linkedin.com/in/huahuiyang/

浙公网安备 33010602011771号