Possible Duplicate:
Getting the class name from a static method in Java
When you are inside of a static method, is there a way to get the class name (a string containing the name) without typing the class name itself?
For example, typing MyClass.class.getName() is no more useful than just "Myclass".
You can do it by creating (not throwing) a new Exception and inspecting its stack trace. Your class will be the zeroth element as it is the origin of the Exception. It kinda feels wrong, but it will work.
You can do the same with the Thread class. This seems cleaner to me, but the line is slightly longer. Your class is now the first element in the stacktrace rather than the zeroth. Thread.getStackTrace() is the zeroth.
On the contrary, if you rename MyClass using your IDE’s refactor function it will replace MyClass.class.getName() with RenamedClass.class.getName(). If you put a string in there you’ll have to do it manually.