This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiler error" Watch "Compiler error" New topic

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
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.
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:
subject: Compiler error
It's not a secret anymore!