This one is accepted:
public class Solution {
public static void main(String[] args) {
log("In main method");
}
public static void log(String s) {
//write your code here
String fullClassName = Thread.currentThread().getStackTrace()[2].getClassName();
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
System.out.println(fullClassName + ": " + methodName + ": " + s);
}
}
This one is not accepted:
public class Solution {
public static void main(String[] args) {
log("In main method");
}
public static void log(String s) {
//write your code here
String fullClassName = Thread.currentThread().getStackTrace()[1].getClassName();
String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
System.out.println(fullClassName + ": " + methodName + ": " + s);
}
}
Same requested output: "com.codegym.task.task09.task0906.Solution: main: In main method"
Why is the only accepted answer the first version?