• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

case statements range???

 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Case statements must have values within permissible range"
Can anybody explain the above statement please...
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by venkatesh badrinathan:
"Case statements must have values within permissible range"
Can anybody explain the above statement please...


Thats self explanatory, In case statement when you switch on different values then they must be in a permissible range , like

if you switch statement takes an int as a parameter then , the case statement must be in a range -2 147 483 648 to 2 147 483 647.
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sagar Rohankar, but still i have some issues.
i think switch case can accept only integer values, although we pass char, byte, short, enum it converts to an int value.. am i right??? please explain
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you are right , in addition to this ;
what Java lang specification says :

Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type (�8.9), or a compile-time error occurs.
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by venkatesh badrinathan:
Thanks Sagar Rohankar, but still i have some issues.
i think switch case can accept only integer values, although we pass char, byte, short, enum it converts to an int value.. am i right??? please explain


This means that if you use a byte variable in switch, then all the values of the case labels must be within the range of byte.
Eg-

The second case label generates an error as the value 178 is not in the range of byte.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic