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

switch - case doubt

 
Mukherji Sandeep
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
switch(var){
case *:
...
}
at var. we can not use double. Why so?
[ December 14, 2008: Message edited by: Mukherji Sandeep ]
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is something that is defined in Java specification. We have to follow it.

As to why it is so, it could be for historical and performance reasons. When translated to java byte codes, and later ran on your platform, they end up in very small and fast machine instructions.

You can also use Enum on it.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type (�8.9), or a compile-time error occurs.

Java Language Specification
 
Mukherji Sandeep
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
many Thanks to both of you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic