1

Example code:

public class test {
    public static void main(String[] args) {
        if (false) {
            System.out.print("if");
        } else if (true) {

            System.out.print("else-if");
        }
    }
}

and set breakpoint like the picture: enter image description here

Then debug it, however, Intellij IDEA doesn't stop at the breakpoint. Why?

This question may be a duplicate of some existing question but I don't think it should be closed as a duplicate of stackoverflow.com/questions/17965562/… because, while the answers may be the same, the questions are phrased differently and only appear as duplicates once you know the answer – Kirby 10 hours ago

and, EVEN IF there exists some compile-time-handle with if statement, the breakpoint should always be hit.

guo
  • 9,674
  • 9
  • 41
  • 79
  • 4
    The whole body of that method is basically compiled down to `System.out.print("else-if");`. All those `if` conditions are constant expressions that can be checked at compile time. – Sotirios Delimanolis Jul 29 '16 at 15:17
  • This question may be a duplicate of some existing question but I don't think it should be closed as a duplicate of http://stackoverflow.com/questions/17965562/javac-code-elimination-capabilities because, while the answers may be the same, the questions are phrased differently and only appear as duplicates once you know the answer – Kirby Jul 29 '16 at 15:53

0 Answers0