Reputation: 1347
I'm having trouble passing an int array to a method right now. They're in the same class, and if I switch the method argument to an int, and then use an int, everything works fine. I'm trying to pass an int[] like this:
setBoardBulk({1, 2}, {1, 2}, {2, 3});
But doing this I get a:
illegal start of experession
not a statement
';' expected
for every element I pass. In this case I have 3 of each because I'm trying to pass 3 arrays. What am I doing wrong here? Thanks!
Upvotes: 0
Views: 51
Reputation: 41281
Assuming setBoardBulk
takes 3 int[]
s, you need to do as follows:
setBoardBulk(new int[]{1, 2}, new int[]{1, 2}, new int[]{2, 3});
The braces are valid at declaration, but need to be a full initializer in other places.
Upvotes: 1
Reputation: 178263
Only on declarations of arrays can you simply say {1, 2}
. With other array initialization expressions, you must explicitly include new int[]
before the braces. Try
setBoardBulk(new int[] {1, 2}, new int[] {1, 2}, new int[] {2, 3});
Upvotes: 3