package org.kodejava.lang;
public class GetCurrentMethodName {
public static void main(String[] args) {
// Get the current executing method name
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
System.out.println("methodName = " + methodName);
GetCurrentMethodName obj = new GetCurrentMethodName();
obj.executeAMethod();
}
private void executeAMethod() {
// Get the current executing method name
String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName();
System.out.println("methodName = " + methodName);
}
}
This program will print out the following string:
methodName = main
methodName = executeAMethod
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024