Random Arrays allowed in Java Syntax?

I'm a bit dumbfounded:

I was writing a little bit of code for my application, and I made a typo. I added square brackets, instead of the p. Smart Eclipse added the other bracket for me. To my surprise, no warning popped up, about any syntax errors.

System.setProperty("apple.laf.useScreenMenuBar", "true");[]
// No Warnings or Errors?!?!?
this.initalize();

I can add them anywhere in constructors and methods, but no where outside of that. I continued experimenting:

this.initalize();[][][]
// this.parent.setJMenuBar(this); 
this.setVisible(true);

I can have multiple arrays...

this.initalize();[[]] // Syntax Error, delete this token
//this.parent.setJMenuBar(this); 
this.setVisible(true);

But nothing nested.

I tried a little more... I get errors in certain places.

JMenuItem help_about = new JMenuItem("About the Developers...");
[] // Error!
help_help.setToolTipText("Access the help center");

Semi-colons make these error-prone:

[]; // Error!

It seems as if I can put these brackets anywhere as long as there is a reserved keyword that follows...

[]
return view; // No Errors here...

Nothing changes as I save the code, restart Eclipse or anything. A little information about my system:

  • Eclipse Luna 4.4.2
  • Compliance Level 1.6
  • Java 7 (I think) Nope! Java Version 1.6.0_65

So, here's my question...

  • Is this a bug with eclipse?
  • Is this something unintended with java syntax?
  • Or, is it...

It's not a bug... It's a Feature!!!

Answers


It is neither a bug of eclipse nor it is a feature provided by java. I ran the same code in Eclipse Luna 4.4.0 and with java 7 and it give me error. As it is commented by Sotirios it is not a valid syntax. On the other hand if you have written ; or {} in the same way you are using [], they will not give you error. But it is because java compiler understand it and they are valid.

So you might be not getting error may be due to some other reasons like may be eclipse have not compiled your code when you saw it error free or may be it is taking too much time for some reason etc.


Need Your Help

Adding a new user field to sfGuard user Admin Form

symfony1 symfony-1.4 symfony-forms sfguard

I am trying to add a custom field to the user form in the sfGuard plugin.

My code is not working as expected

php mysql

I am trying to insert some data from form to database . I know how to retrieve values but the thing is that I need to insert the data into a certain order.