"The left hand side of an assignment must be a variable" due to extra parentheses

Posted by polygenelubricants on Stack Overflow See other posts from Stack Overflow or by polygenelubricants
Published on 2010-03-24T03:06:55Z Indexed on 2010/03/24 3:23 UTC
Read the original article Hit count: 403

Filed under:
|
|
|

I know why the following code doesn't compile:

public class Main {
   public static void main(String args[]) {
      main((null)); // this is fine!
      (main(null)); // this is NOT!
   }
}

What I'm wondering is why my compiler (javac 1.6.0_17, Windows version) is complaining "The left hand side of an assignment must be a variable".

I'd expect something like "Don't put parentheses around a method invokation, dummy!", instead.

So why is the compiler making a totally unhelpful complaint about something that is blatantly irrelevant?

Is this the result of an ambiguity in the grammar? A bug in the compiler?

If it's the former, could you design a language such that a compiler would never be so off-base about a syntax error like this?

© Stack Overflow or respective owner

Related posts about compiler

Related posts about error-message