Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Object o = // whatver object you want to interrogate
Class c = o.getClass();
java.lang.refelct.Method[] methods = c.getDeclaredMethods();
public class WhereAmI {
/** tells me which method called me */
public static String tellMe() {
Exception e = new Exception();
StackTraceElement all[] = e.getStackTrace();
if (all.length < 2) // WFT am I then, should be at least 2!
return "";
return all[1].getMethodName();
}
}
public class Confused {
public static void main(String args[]) {
Confused c = new Confused();
c.someMethod();
c.otherMethod();
}
public void someMethod() {
System.out.println(WhereAmI.tellMe());
}
public void otherMethod() {
System.out.println(WhereAmI.tellMe());
}
}