Reputation: 1233
I am trying to pass an array of boolean values to a method. This code works:
void checkResults(boolean[] isChecked){
//Do something
}
boolean[] isChecked= {true, true};
checkResults(isChecked); //works
But all attempts below failed:
checkResults(new {true, true}); //Compile time error
checkResults({true, true}); //Compile time error
checkResults(true, true); //Compile time error (this one is obvious)
Is there a way to create an array in arguments and pass to a method in one line?
Upvotes: 0
Views: 56
Reputation: 4948
You can create an anonymous array like this and pass the same.
checkResults(new boolean[]{true, true});
Upvotes: 3