Why does Eclipse generate .class file if there is a syntax error in my Java source file?
eclipse, java
Solution
There is a reason. It allows applications with compilation errors to be run (sort of!). What the compiler does is to create stub methods for any methods that it cannot compile due to errors in the source code. If the application calls one of these stub methods, you get a runtime exception that says that the method had a compilation error.
IMO, this "feature" is mostly harmful ... and it can be very confusing for Eclipse newbies. However, it can be useful for people who want to runtests, etc on partly written classes.
IIRC, there is a checkbox in the Run dialogs that allows you to enable / disabling running applications that have compilation errors. (I always disable it!)
UPDATE
This behaviour is Eclipse specific. It is controlled by a setting in the "Window > Preferences > Run/Debug > Launching" preference panel.
Problem
When I am creating my project using the Eclipse IDE it is generating a class file even when there is a syntax error in my code? ``` class Test { public void test(String value) { System.out.println("TEST CALLED WITH VALUE " + value); } } class Abc { Test obj = new Test(); public String firstCallToMethodFromTest() { System.out.println("FIRST CALL TO THE METHOD FROM TEST CLASS"); String result = obj.test("TEST"); return result; } public String secondCallToMethodFromTest() { System.out.println("SECOND CALL TO THE METHOD FROM TEST CLASS"); String result = obj.test(); // There is no such method in test class i.e source code error return result; } } ``` Method `firstCallToMethodFromTest` is called as an action method from my Struts action. How does Eclipse make it possible to compile code for the `Abc` class where there are syntax errors in my source code file?