我遵循了該線程中提出的要點(diǎn),但是出現(xiàn)錯(cuò)誤“對(duì)于參數(shù)類型,運(yùn)算符未定義[...]”我的代碼:public class Test{private int[] array = new int [5]; public int method(int i) { for(int s = 0; s <= array.length; s++) { if( array[s] != null) { //I get the error in here even though the highest upvoted answer in the linked question recommends this solution. I obviously cant check it for 0, because the user input can be 0. array[s] = i; } else { method(i); } } }}
2 回答

繁星coding
TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊
您將收到此錯(cuò)誤,因?yàn)?code>int它是原始類型。在您的情況下,array[s]
返回int
而不是Integer
。Int
不能是一個(gè)null
。
從改變你的陣列int[]
來Integer[]
,如果你想查詢?yōu)榭铡?/p>
private Integer[] array = new Integer[5];
添加回答
舉報(bào)
0/150
提交
取消