aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiler error" Watch "Compiler error" New topic
Author

Compiler error

Lakshmi Saradha
Ranch Hand

Joined: Oct 21, 2003
Posts: 170
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?


Thanks,<br />Lakshmi.
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
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;


"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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.


SCJP2. Please Indent your code using UBB Code
Lakshmi Saradha
Ranch Hand

Joined: Oct 21, 2003
Posts: 170
Thank you vishy and Jose
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiler error