• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiler error

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you vishy and Jose
reply
    Bookmark Topic Watch Topic
  • New Topic