Let's take the following example:
public class Test {
public void main(String[] args) {
int[] someInts = {1, 2, 5};
new Dummy(1, someInts, "Hello"); //works
new Dummy(1, new int[] {1, 2, 5}, "Hello"); //works
new Dummy(1, {1, 2, 5}, "Hello"); //fails
new Dummy(1, [1, 2, 5], "Hello"); //fails
}
public class Dummy {
Dummy(int someNumber, int[] someArray, String message) {
}
}
}
For both failing lines, Eclipse says: "The constructor Test.Dummy(int, int, int, int, String) is undefined"
Firstly, I don't understand why it doesn't recognize the array as an array (in the failing lines only).
Secondly, why can I not pass the array directly into the constructor, but instead have to create a variable to pass it?
And thirdly, is there a way to create a constructor which takes something like that line in question, meaning without a variable or a new int[] {...} statement?
If someone knows a better way to formulate this in the title, feel free to improve it.