【发布时间】:2016-07-24 01:50:54
【问题描述】:
我正在尝试将一个布尔值数组传递给一个方法。此代码有效:
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})吗?