Search code examples
javaintellij-ideacompiler-construction

Why can IntelliJ detect missing semi-colons and Java compiler can't?


I was wondering why that's the case. How and why IntelliJ is able to detect missing semi-colons and Java compiler can't? Is there a case where IntelliJ is wrong and there is no way to actually detect missing semicolon? I read similar question discussing C and C++, there are pointers which complicate things, but Java seems simpler in that matter.


Solution

  • I would like to challenge your premise that a Java compiler cannot detect missing semicolons. I just tried to compile the following code with javac from Oracle JDK 8, and it is perfectly able to detect the missing semicolon:

    public class Test {
      public static void main(String... args) {
        System.out.println()
      }
    }
    

    The compiler error printed is the following:

    Test.java:3: error: ';' expected
        System.out.println()
                            ^
    1 error
    

    As you can see, it not only detected the missing semicolon, it was even able to point out exactly where it was missing.