[問題]請問JAVA的方法是不是不能用static int

作者: SST2000 (BMW 428i)   2020-01-20 13:29:40
請問一下
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??
作者: NintendoGC (Goston)   2020-01-20 13:47:00
static 變數請在 class 層級宣告
作者: mintle (☑狂派☑初音)   2020-01-20 14:05:00
你在方法內宣告靜態是很奇怪的事情
作者: pupudice (poopoodice)   2020-01-20 16:10:00
本地變數可以用static嗎
作者: ssccg (23)   2020-01-20 17:15:00
java沒有C/C++的那種static只有class層級有static member
作者: gpctv (gpctv)   2020-01-22 23:43:00
不是阿!你的method 已經是static了啊!
作者: hpa82228   2020-01-23 13:34:00
你已經宣告這個方就是靜態,裡面的不用再宣告了

Links booklink

Contact Us: admin [ a t ] ucptt.com