• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String in switch case

 
Asvin Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cant use String in switch case, allows types are int and char.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Asvin Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic