How eclipse execute java code when there are compile errors

前端 未结 3 934
难免孤独
难免孤独 2021-01-21 05:25

When the following java code is executed in eclipse, it gives the correct output (i.e. prints \'Class B\'), but according to java specification, the code cannot be compiled (sin

相关标签:
3条回答
  • 2021-01-21 05:58

    Eclipse shouldn't do that. It leads to ambiguous results. If a class couldn't be compiled, then its corresponding .class file should be removed.

    If you check the bin folder, B.class and A.class are present. Not sure why it creates B.class even though B doesn't compile

    0 讨论(0)
  • 2021-01-21 06:01

    Eclipse uses its own Java compiler (called ecj) instead of javac. This compiler allows (partial) compilation of broken source files.

    0 讨论(0)
  • 2021-01-21 06:07

    Actually, eclipse tries to compile the class and its not able to compile due to build errors, when you simply run those files it executed the previously compiled class, that were successfully compiled earlier (eclipse tries to compile and build the files on every save as per generic settings).

    in order to resolve you can try clean the project before running, while in case of javac, it simply compiles ,

    0 讨论(0)
提交回复
热议问题