Reputation: 742
The first snippet is from the java class I wrote, and the second is from the decompiled jar file that contained the class. What I noticed is that the post increment is now pre increment, and this is probably affecting my feature.
if (uiType.equals("structure")) {
NodeList images = doc.getElementsByTagName("img");
for (int i = 0; i < images.getLength(); i++) {
Node img = images.item(i);
Element imgEle = (Element) img;
String srcUrl = imgEle.getAttribute("src");
if (srcUrl.startsWith("image")) {
srcUrl = appUrl+"/common/"+srcUrl;
}else {
continue;
}
imgEle.setAttribute("src", srcUrl);
}
if (str5.equals("structure"))
{
Object localObject3;
Object localObject5;
Object localObject7;
Object localObject9;
localObject1 = localDocument.getElementsByTagName("img");
for (int i = 0; i < ((NodeList)localObject1).getLength(); ++i) {
Node localNode = ((NodeList)localObject1).item(i);
localObject3 = (Element)localNode;
localObject5 = ((Element)localObject3).getAttribute("src");
if (((String)localObject5).startsWith("image")) {
localObject5 = str6 + "/common/" + ((String)localObject5);
((Element)localObject3).setAttribute("src", (String)localObject5);
}
}
}
Upvotes: 2
Views: 97
Reputation: 43391
It doesn't affect your program, because the increment is "by itself." The only difference between the two expressions is the value of i
as seen by other expressions in the same statement; since there are no other expressions (the entire statement is just the increment, i++
), post- and pre- look the same as far as you can see them.
The reason you're seeing this is that ++i
is slightly more efficient, since it doesn't need to remember the old value of i
. It's a very simple compiler optimization, one of the few that javac will actually perform (most optimizations are done by HotSpot at run time).
You can generally trust javac to not break your program; it's a pretty well-tested compiler, and it would be very surprising if it broke something as basic as a for
loop.
Upvotes: 3
Reputation: 73548
No, it doesn't affect your code in any way.
Even though the standard idiom in a for-loop is int i = 0;i < 10; i++
, the behaviour is identical if the last term is a preincrement.
Upvotes: 3