My question is close to this one but not quite the same.
I have an inherited (as in, I can't/won't change it) array of parameters in my class like so:
public double[] params;
The class utilises these parameters in complex ways, so I would prefer to have human-readable names for each element in the array. In C, you would do something like this
#define MY_READABLE_PARAMETER params[0]
I am also aware that in Java I could create a bunch of constants or an enumerator with attributes. Then, to access a parameter I'd have to type something like this:
params[MY_READABLE_PARAMETER]
This is acceptable but I would really like to omit the array name altogether. Is it possible?
Yes, it is possible simply by not using an array:
double myReadableParameter;
double anotherReadableParameter;
If you need to access them as a collection, you can always put them in a list.
Is there any reason you couldn't do this?
...
public double getMyReadableParam() {
return params[0];
}
public void setMyReadableParam(double value) {
params[0] = value;
}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With