作者hijje ( )
看板java
標題[問題] 請問this.getClass().getName()的用法
時間Sun Nov 22 23:06:31 2009
public class a{
public static void main( String arg[] ) {
System.out.println( this.getClass().getName() );
}
}
-------- 以上是全部的程式碼
以下是compile後的結果
a.java:4: non-static variable this cannot be referenced from a static context
System.out.println( this.getClass().getName() );
^
1 error
請問一下這樣子的寫法哪裡出錯了呢
tks !!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.93.193
推 PsMonkey:關鍵字 static 11/22 23:14
→ hijje:原來是static和non-static的問題 不是getClass().getName() 11/22 23:40
→ hijje:改成建構式就沒問題了 tks !! 11/22 23:42
推 PsMonkey:錯誤訊息不就告訴你了 == 11/23 00:09