如何获取调用Java中另一个类的特定方法的类的名称?
LogWindow.java
public class LogWindow extends JFrame{
public static void append(String text, JTextArea textArea) {
if (text == "Clear")
textArea.setText(null);
else {
textArea.append(Time.current() + text + "\n");
textArea.setCaretPosition(textArea.getText().length());
}
}
}
Dispatch.java
public class Dispatch {
public Vehicle getClosest(loadAttribute load, Vehicle[] OHT) {
String className = Thread.currentThread().getStackTrace()[1].getMethodName();
String methodName = "." + Thread.currentThread().getStackTrace()[1].getClassName();
String text = className + methodName + "method running";
LogWindow.append(text, LogWindow.totalNodeText);
...
}
}
从另一个类或方法调用LogWindow.append时,不仅是调度类 我想打印从LogWindow.append调用的类或方法的名称。
例如,如果您在Dispatch.getClosest中运行LogWindow.append 我想在textArea中打印类(Dispatch)和方法(getClosest)的名称