In processing, I have defined the following class:
class SomeClass {
SomeClass(int[] someArray) {
println(someArray);
}
}
Now I would like to create an instance of that class, but I am having trouble getting the array passed to the constructor:
SomeClass myVar = new SomeClass({
12, 10
});
But this always gives me an error "unexpected token: {". So apparently defining the array "on the fly" does not work.
However, this will work:
int[] dummy = {12, 10};
SomeClass myVar = new SomeClass(dummy);
But I find it rather stupid to declare this array outside of the object, because this leads to all kinds of trouble when creating multiple objects:
int[] dummy = {12, 10};
SomeClass myVar = new SomeClass(dummy);
dummy = {0, 100};
SomeClass myVar2 = new SomeClass(dummy);
Both instances of the class now have a reference to the same array {0, 100}
which is certainly not what I intended to do.
So my question is: how does one correctly pass an array to the constructor of a class without having to declare the array before? Is it even possible?
Thank you for your answers!