• 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

Optional semicolon in enumerated type declaration "when no other declarations for thi

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranch People

First off, please forgive me, should the following be a recurring question. But I spent several hours today in order to work out what I don't understand and I couldn't find a satisfying clue so far. My question concerns enumerate types and the optional semicolon.

Sierra/Bates SCJP Study Guide for Java 5.0 (I bought my copy in June 2007) says on page 62: ... made it optional to put a semicolon at the end of the enum declaration, when no other declarations for this enum follow:



I'm about to loose my way because of "when [reads 'if'] no other declarations for this enum follow". Shouldn't this read "where [or because] no other declarations for this enum follow". Since the semicolon is already outside the curly brackets that define the body of the enumerated type declaration, how can any piece of code be assigned to CoffeeSize? (I ought to say, that I'm somtimes uncertain wether "enum" means "enumerated type" or "an element of the enumerated type".) Due to the recent errata list for the Study Guide, the above statement is correct; see https://coderanch.com/t/257589/java-programmer-SCJP/certification/SCJP-Errata-Updated

Could I ask you for an example, where the semicolon in



is mandatory because "other declarations for this enum follow"? From my point of view, the constant-specific-class-body-code on page 65 is not(!) what I need, since the semicolon there separates the list of constant values from the constructor "CoffeeSize(int ounces) {...}" and what comes after that.

Best regards,

Ralf

[ March 24, 2008: Message edited by: Ralf Wahner ]

[ March 24, 2008: Message edited by: Ralf Wahner ]
[ March 24, 2008: Message edited by: Ralf Wahner ]
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it's a misprint in the book. The semicolon should be inside the curly braces. Here is from the JLS 8.9 Enums

As you see the rule is that if an enum has an EnumBodyDeclarations then the semicolon is required.
With the optional , and ; the code in the example can be
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles with the semicolon on the outside of the curlies too.
 
Ralf Wahner
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Irina

Thank you very much for your reply, especially for the link to the language specification. I should form a habit of searching there before posting. :-( I believe that your argument is reasonable and I would like to tell the authors about that. As with enums, declarations of classes, interfaces and methods also accept a semicolon righthand of the closing curly brace, even though we have no benefit from that; from my point of view. Therefore, "enum {...};" most probably is not, what the authors mean. Again, thanks a lot; I take your attention and helpfulness as a good example. :-)

Best regards,

Ralf
 
We can walk to school together. And we can both read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic