Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiler error

 
Lakshmi Saradha
Ranch Hand
Posts: 170
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you vishy and Jose
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic