*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch - case doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "switch - case doubt" Watch "switch - case doubt" New topic
Author

switch - case doubt

Mukherji Sandeep
Greenhorn

Joined: Dec 09, 2008
Posts: 6
switch(var){
case *:
...
}
at var. we can not use double. Why so?
[ December 14, 2008: Message edited by: Mukherji Sandeep ]

Mukherji Sandeep<br />Trying Hard to learn java
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2053
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

Joined: Oct 25, 2008
Posts: 2700

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


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Mukherji Sandeep
Greenhorn

Joined: Dec 09, 2008
Posts: 6
many Thanks to both of you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: switch - case doubt