I cannot decide which method is better with consideration of both readability and fault-tolerance.
Method #1:
Object[] objects = getArrayOfKnownLength();
int i = -1;
someMethod(objects[++i], objects[++i], objects[++i], objects[++i]);
Method #2:
Object[] objects = getArrayOfKnownLength();
someMethod(objects[0], objects[1], objects[2], objects[3]);
I have always done the second method, but there have been several cases where I got IndexOutOfBoundsException because I made some changes which affected the expected array element position. So I have been considering using the first method to prevent this issue. My only concern is that it may be less readable.
I know this is a very minor thing to be questioning, but I am curious what the majority opinion is.
IndexOutOfBoundsException
.