2016-07-24 11 views
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) 

は、引数の配列を作成し、1行でメソッドに渡す方法はありますか?

+2

'checkResults(new boolean [] {true、true})'を試したことがありますか? – VatsalSura

答えて

3

このような無名配列を作成して渡すことができます。

checkResults(new boolean[]{true, true}); 
関連する問題