This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiler error

 
Lakshmi Saradha
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this piece of code not showing a compiler error at line?
class a
{
static void foo(int i) {}; //line 1
void m1()
{
}
}
Is the semi-colon allowed there?
 
Vishy Karl
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think ; by itself is allowed anywhere as long as it is not disturbing the expected syntax
For example foll. code snippet is valid
if(i==1)
{
System.out.println("hi");;;;;;;;;;;;
}
and
if(false);
{
System.out.println("hi");
}
O/p is hi as if condition is changed into a statement.
but it won't work here
public static void main(String args[]);
Did not get anything reg. this in JLS. Hope others too can help.
Good luck;
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishy you are right, from JLS
_________________________________________________________________
14.6 The Empty Statement
An empty statement does nothing.
EmptyStatement:
;
Execution of an empty statement always completes normally.
_________________________________________________________________

A succession of empty statements is ok for the compiler.
 
Lakshmi Saradha
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you vishy and Jose
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic