Given the following code:
public class MainClass {
public static int f(){
int i=0;
i++;
return i;
}
}
the compiler javac produces the following code:
Compiled from "MainClass.java"
public class latte_jvm.MainClass {
public static int f();
Code:
0: iconst_0
1: istore_0
2: iinc 0, 1
5: iload_0
6: ireturn
}
Function f does really simple thing - it just returns 1. It's so directly translated that it makes me hard to believe that java compiler does any optimizations at all. Why java compiler creators decided to not do such optimizations in the compilation phase?