理解錯誤:預期.class
編譯過程中,當編譯器遇到預期表達式的型別(例如int 或int[ ])。從語法上講,這意味著唯一可接受的符號是 。其次是類。
錯誤原因
此錯誤是由於編譯器混亂而發生的。語法檢查偵測到需要表達式的類型,從而產生“.class”預期訊息。
錯誤範例
double d = 1.9; int i = int d; // error: '.class' expected ^
解決這錯誤
double d = 1.9; int i = (int) d; // Correct: type casts `1.9` to an integer
int j = someFunction(a); // Correct ... assuming 'a' type is compatible for the call.
someMethod(array[]);
數組參考:
someMethod(array); // pass reference to the entire array
someMethod(array[someExpression]); // pass a single array element
int i = someMethod(int j); // Error
方法中的參數聲明:
int i = someMethod(j);
刪除範圍聲明:
int[]; letterCount = new int[26];
int[] letterCount = new int[26];
刪除分號:
return integers[];
return integers;
類型聲明符而不是表達式:
return integers[someIndex]; // Return one element of the array
或
if ((withdraw % 5 == 0) && (acnt_balc >= withdraw + 0.50)) double cur = acnt_balc - (withdraw + 0.50); System.out.println(cur); else System.out.println(acnt_balc);
if ((withdraw % 5 == 0) && (acnt_balc >= withdraw + 0.50)) { double cur = acnt_balc - (withdraw + 0.50); System.out.println(cur); } else { System.out.println(acnt_balc); }
以上是為什麼我會收到 Java 編譯器錯誤'\'.class\'預期\”?的詳細內容。更多資訊請關注PHP中文網其他相關文章!