How to get the current class name in Java?

Posted by Jessica Taylor | Updated on

If you want to get the current class name in Java? The "$1" is not “useless non-sense”. If your class is anonymous, a number is appended. If you don’t want the class itself, but its declaring class, then you can use getEnclosingClass().

For example:

But note that this is not the current class name. The anonymous class is different class than its enclosing class. The case is similar for inner classes.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers