• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

semicolon in Enums

 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
enum EnumCoffee {

BIG,HUGE,OVERWHELMING; //Line1
}; //Line2

I know that semicolon at LIne 2 is optional. Isthe semicolon at Line1 also optional.
 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is optional. It will work both ways.
But why do you want to introduce a semicolon there at Line1? Just playing around with code I hope.
 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through a test And I got enum question. There was no semicolon at all in the programm. I was confused where it is optional....
 
Rafael Angarita
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The semicolon at Line 1 would be mandatory if there were more code following that line.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Banu Chowdary wrote:I know that semicolon at LIne 2 is optional. Isthe semicolon at Line1 also optional.

AFAIK it's not optional if you have fields, constructors, and / or methods in the enum after the enum constants. If you have any of these critters, then you will absolutely need the semicolon on Line1.

edit: as Rafael points out just before I did .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic