File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • 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
  • 0
  • 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
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 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
  • 0
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic