| Author |
String in switch case
|
Asvin Kumar
Greenhorn
Joined: Mar 01, 2010
Posts: 13
|
|
I want to use a string in switch case and I get the following error,
[javac] UserData.java:58: incompatible types
[javac] found : java.lang.String
[javac] required: int
[javac] switch(type)
any help??
|
 |
Shinelin Samuel
Ranch Hand
Joined: Mar 01, 2010
Posts: 55
|
|
|
You cant use String in switch case, allows types are int and char.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Actually, int and everything that is assignable to int. That includes char, short and byte. Since Java 5.0 enums can also be used in switch statements, and Java 7 may (finally?) introduce the switch statement for Strings. It has been discussed, but I don't know what the status on that is.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Asvin Kumar
Greenhorn
Joined: Mar 01, 2010
Posts: 13
|
|
|
Thanks for your replies...
|
 |
 |
|
|
subject: String in switch case
|
|
|