In-loop declarations and performance question ...
Consider the following two code snippets in which vect is a vector of objects of type Thing.
Snippet 1:
Code:
for (Enumeration<Thing> en = vect.elements(); en.hasMoreElements(); )
{
Thing item = en.nextElement();
//Rest of code here.
}
Snippet 2:
Code:
Thing item;
for (Enumeration<Thing> en = vect.elements(); en.hasMoreElements(); )
{
item = en.nextElement();
//Rest of code here.
}
In the case of Snippet 1, is there any extra overhead associated with placing the declaration of item in the loop rather than outside, as in Snippet 2? Or is there no difference?