• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Semicolon after any member declaration ?

 
Pierluigi Di Giacomo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic