You can use your constructor as a parameter and check its size to make sure that it is the expected one.varargs double
Sort of:
public class Foo {
private double A;
private double B;
...
private double K;
public Foo(double... coordinates) {
if (coordinates == null || coordinates.length != 11) {
throw new IllegalArgumentException("Unexpected size of coordinates");
}
this.A = coordinates[0];
this.B = coordinates[1];
...
this.K = coordinates[10];
}
...
}
This way, you only have one parameter defined in your constructor , but you can still provide values 11for simplicity as follows:
Foo foo = new Foo(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0);
And you can still provide it as arrayof doubleas follows:
Foo foo = new Foo(new double[]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0});
source
share