aspose file tools*
The moose likes Beginning Java and the fly likes Semicolon after any member declaration ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Semicolon after any member declaration ?" Watch "Semicolon after any member declaration ?" New topic
Author

Semicolon after any member declaration ?

Pierluigi Di Giacomo
Greenhorn

Joined: Jan 18, 2012
Posts: 13
Hello ranchers,
I was looking at the part of the Java Spec which deals with class body and member declarations, and found that all those marked as ClassMemberDeclaration require a mandatory semicolon at the end of their declaration. The semicolon is mandatory because it lacks a subscripted "opt". This is a little surprising, as I've never had to add a semicolon after writing an inner class, a method, or an inner interface as part of a class. AFAIK only fields require it... Am I misunderstanding something in the syntax used by the Spec ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Pierluigi Di Giacomo wrote:Hello ranchers,
I was looking at the part of the Java Spec which deals with class body and member declarations, and found that all those marked as ClassMemberDeclaration require a mandatory semicolon at the end of their declaration.


You mean this?


That's an either/or for any one of those things. So a ClassMemberDeclaration is either a FieldDeclaration or a MethodDeclaration or a ClassDeclaration or an InterfaceDeclaration or a semicolon.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jeff Verdegan wrote:
Pierluigi Di Giacomo wrote:Hello ranchers,
I was looking at the part of the Java Spec which deals with class body and member declarations, and found that all those marked as ClassMemberDeclaration require a mandatory semicolon at the end of their declaration.


You mean this?


That's an either/or for any one of those things. So a ClassMemberDeclaration is either a FieldDeclaration or a MethodDeclaration or a ClassDeclaration or an InterfaceDeclaration or a semicolon.


If ClassMemberDeclaration required a semicolon after those options, it would look like


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
I am glad somebody can read this pseudo-BNF, because I didn’t get that bit at all.

And welcome to the Ranch
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Jeff Verdegan wrote:
If ClassMemberDeclaration required a semicolon after those options, it would look like


Or it could put the semicolon requirement inside each of the respective options, so that you'd have to look at each individual definition to find out the complete story. In this case FieldDeclaration does require a semicolon, but the other three do not.
Pierluigi Di Giacomo
Greenhorn

Joined: Jan 18, 2012
Posts: 13
Thank you all for the explanations. Actually I knew that each of ClassMemberDeclaration entries were "either/or", but for some reason I didn't look at the ";" as an entry like the others.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2397
    
  28

Wait! There are people who read that part of the spec? :lol: I've always skimmed over the BNF and looked at the examples instead
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mike Simmons wrote:
Jeff Verdegan wrote:
If ClassMemberDeclaration required a semicolon after those options, it would look like


Or it could put the semicolon requirement inside each of the respective options,


Which is what it did.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Semicolon after any member declaration ?