سؤال

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!

هل كانت مفيدة؟

المحلول

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});

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top