Say I have a class called MyClass
, within this class, I want to find out the class name that instantiated an object of MyClass
, for example:
class MyClass {
final String whoCreatedMe;
public MyClass() {
whoCreatedMe = ???
}
}
public class Driver {
public static void main(String[] args) {
System.out.println(new MyClass().whoCreatedMe); // should print Driver
}
}