All I am trying to do is to get the current class name, and java appends a useless non-sense $1 to the end of my class name. How can I get rid of it and only return the actual class name?
String className = this.getClass().getName();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:You can move that in some static utility method.
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.