I am using Neatbeans 7.0 for Java programming. I have written a Switch case for selection of the program.
switch(menu)
{
case 1:
{
//stmt
}
default:
{
//stmt
return;
}
}
I am getting compile time error at switch(menu)
The Error is "strings in switch are not supported in -source 1.6
(use -source 7 or higher to enable strings in switch)
(Alt-Enter shows hints)” Can any one please help me on this.
I’m assuming here that
menuis a string type, though it doesn’t really match your case statements. Allowing the use of strings inswitchstatements was added in Java 7.You can either switch to Java 7 and fix the
caseso that it checks against a string rather that the integral1, or convertmenuto an integer and check that, such as withInteger.ParseInt(), something like: