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

沒有留言:

張貼留言

[設計軟硬件] 2026年3月份關於設計軟硬件價錢的資料搜集

Hardware Macbook Pro 16吋 M5 Pro 銀色 標準顯示器 48GB RAM 2TB SSD Storage HK$27,999 Arduino Hardware with sensors & software for control TaoBao ...