I have a trivial, but irritating problem in Java. Suppose we have the following class and method:
class A{
void doSth(int[] array){
int index1, index2, index3;
int value1, value2, value3;
if(array[index1] > 10){
//Long code modifies value1, value2, value3
}
if(array[index3] > 100){
//Same long code modifies value1, value2, value3
}
if(array[index2] > 20){
//Same long code modifies value1, value2, value3
}
}
Disregarding what this is trying to achieve, I would like to somehow make this redundancies disappear. usually, I would pass the values to a hlper method, but I can't, since the block is modifying local variables. Any idea how to simplify this?