Are random arrays allowed in Java syntax?

I am a little stunned:

I wrote some code for my application and I made a typo. I added square brackets, not p. Smart Eclipse added another bracket for me. To my surprise, there were no warnings about any syntax errors.

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

I can add them anywhere in the constructors and methods, but not somewhere outside of this. I continued to experiment:

 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 is invested.

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"); 

Half-columns make these errors vulnerable:

 []; // Error! 

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

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

Nothing changes when you save the code, restart Eclipse or something else. Some information about my system:

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

So here is my question ...

  • Is this an eclipse bug?
  • Is this something unintentional with java syntax?
  • Or that...

This is not a mistake ... This is a feature !!!

+5
source share
1 answer

This is not an eclipse error or a function provided by java.
I ran the same code in Eclipse Luna 4.4.0 and with java 7 and it gave me an error.
Since it is commented on by Sotirios, this is an invalid syntax.
On the other hand, if you wrote ; or {} just like you use [] , they won’t give you an error. But this is because the java compiler understands this, and they are valid.

This way you may not be mistaken, maybe due to some other reasons, for example, maybe eclipse did not compile your code when you saw it without errors, or maybe it takes too much time for some reason, etc. .d.

0
source

All Articles