0
我想傳遞一個布爾值數組到一個方法。此代碼的工作:如何將新數組作爲參數傳遞給Java中的方法?
void checkResults(boolean[] isChecked){
//Do something
}
boolean[] isChecked= {true, true};
checkResults(isChecked); //works
但下面的所有努力都失敗了:
checkResults(new {true, true}); //Compile time error
checkResults({true, true}); //Compile time error
checkResults(true, true); //Compile time error (this one is obvious)
有沒有一種方法來創建參數數組並傳遞給方法在一條線?
你試過checkResults(new boolean [] {true,true})嗎? – VatsalSura