Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

behavior of switch statement with enums

 
Jack McLaren
Greenhorn
Posts: 13
Mac Mac OS X Mac PPC
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it prints "sunday"

why not

"default
final float
sunday"
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jobless jack wrote:
it prints "sunday"

why not

"default
final float
sunday"

Time for you to get to know the Java Language Specification. See section 14.11.
 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The position of the default statement doesn't matter - it's still only executed if none of the case conditions match (as your example shows).

One reason why it's a really bad idea to put it anywhere other than at the end of the switch statement.

 
Jack McLaren
Greenhorn
Posts: 13
Mac Mac OS X Mac PPC
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:The position of the default statement doesn't matter - it's still only executed if none of the case conditions match (as your example shows).

One reason why it's a really bad idea to put it anywhere other than at the end of the switch statement.



thank you

now i understand, how this program works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic