Class<?> enclosingClass = getClass().getEnclosingClass();
if (enclosingClass != null) {
System.out.println(enclosingClass.getName()); // the declaring class name
} else {
System.out.println(getClass().getName()); // this class is anonymous
}
Or,
String className = this.getClass().getSimpleName(); // if this is not
//an anonymous class, else return ""
http://stackoverflow.com/questions/6271417/java-get-the-current-class-name
沒有留言:
張貼留言