I have to write a method which can be called in any class to get the name of the class which is calling the method. The return type should be Class
, so I can use it for another method. So that is what I have right now, but I think its not a clean code. Maybe there is way to use
public class Vlogger{
public static Class getInstance() throws ClassNotFoundException {
String className =new Exception().getStackTrace()[1].getClassName();
return Class.forName(className);
}
}