I have classes similar to these:
class MyClass1 {
static MyObject obj = new MyObject();
public static void doSomething()
{
MyClass1.obj.print();
MyClass2.obj.print();
}
}
class MyClass2 {
static MyObject obj = new MyObject();
public static void doSomething()
{
MyClass1.obj.print();
MyClass2.obj.print();
}
}
public class MyObject {
public void print()
{
System.out.println("Which object called me?");
}
}
From the print function in MyObject, how can I determine which object called the print function, the one in MyClass1, or the one in MyClass2?
Using a stack trace, I was only able to find the function that the print method is inside of and the class of the function that the print method is inside of.