看板 java 關於我們 聯絡資訊
請問一下 public static int showString(ArrayList<Integer> arrayList) { static int counter=0; System.out.println("_________________________________________________"); System.out.println("arraysize is="+arrayList.size()); char[] CH = new char[arrayList.size()]; for (int loop = 0; loop < arrayList.size(); loop++) { CH[loop] = byteAsciiToChar(arrayList.get(loop)); } 請問我在JAVA的方法裡面設定一個靜態變數static int counter 為什麼顯示語法錯誤??? 而且我在Main()裡面寫static counter=0一樣不可以??WHY?? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.246.156.168 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1579498182.A.5D6.html
NintendoGC: static 變數請在 class 層級宣告 01/20 13:47
mintle: 你在方法內宣告靜態是很奇怪的事情 01/20 14:05
pupudice: 本地變數可以用static嗎 01/20 16:10
ssccg: java沒有C/C++的那種static 01/20 17:15
ssccg: 只有class層級有static member 01/20 17:16
gpctv: 不是阿!你的method 已經是static了啊! 01/22 23:43
hpa82228: 你已經宣告這個方就是靜態,裡面的不用再宣告了 01/23 13:34