Bytecode of method variables
Having installed the Bytecode Outline Eclipse plugin, and read the online instruction reference it would appear that the following two code extracts produce similar bytecode:
for (final java.util.Iterator iter = categories.iterator(); iter.hasNext();) {
final String s = (String)iter.next();
}
String s=null;
for (final java.util.Iterator iter = categories.iterator(); iter.hasNext();) {
s = (String)iter.next();
}
ALOAD appears to be used in both cases, implying that there is no performance advantage gained by moving the String outside the for loop