2015年2月10日 星期二

[Java] Get Class Name

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

沒有留言:

張貼留言

日常秘技小輯錄

媽媽傳授: 用爉燭塗在線上縫紉,可以更容易打結,以及拉縫線更順 爸爸傳授: 貼玻璃紙前在玻璃面塗上肥皂水,可以移動玻璃紙不留摺痕