Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum syntax

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that you can write

enum Test { one , two };

or

enum Test { one, two }

and both compile (with trailing semi-colon and without)

Is that correct, the semi-colon is option with an enum declaration?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enum is just an special form of a class definition (that's why they can have constructors, methods and fields) and class definitions don't need a ; at the end.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:
An enum is just an special form of a class definition (that's why they can have constructors, methods and fields) and class definitions don't need a ; at the end.


Thanks! I didn't realize it was optional for class definitions as well!
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, despite the two SCJP certificates I have, I didn't think it was legal either. I thought it would be seen as an empty statement, which is not allowed outside methods / constructors / static blocks / initializer blocks, let alone outside classes. Apparently it isn't in this case.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suspect it happens to be legal because of some inline-class syntax, but you'd have to dig into the minutia to ferret it out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic