サンプル

public class ClassA {

public void methodA ( List list ) {

for ( Iterator it = list.iterator(); it.hasNext(); ) {

int anInteger = 2;
Object obj = it.next();

// do something with obj and anInteger...
}
}


解決策
ループ条件に依存しない変数の宣言または代入を、ループ内で行わない
可能な場合、余分なコストの負担を避けるため、ループ外で代入してください。

public class ClassA {

public void methodA ( List list ) {

int anInteger = 2;
Object obj;
for ( Iterator it = list.iterator(); it.hasNext(); ) {

obj = it.next();

// do something with obj and anInteger...
}
}