Why doesn't Hotspot JIT optimize-out code that has no external effects?

23 Views Asked by At
public class Test {
    public static void main(String[] args) {
        getTheAnswer();
    }

    static int getTheAnswer() {
        int s = 0;
        for (int i = 3; i < 10; i++) {
            s += i;
        }
        return s;
    }
  }

Could be optimized to a no-op. It doesn't produce anything.

0

There are 0 best solutions below