我希望能够打印调用方法名称而不是包含打印方法的方法。有没有办法做到这一点?
private void printOrderNumber() {
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
System.out.println(methodName);
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("variableOutput.txt", true)));
out.println(methodName);
out.println(var1);
out.println("");
out.close();
} catch (IOException e) {
//oh noes!
}
}
private void order1(){
printOrderNumber();
}