Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String in switch java

Tags:

java

java-7

switch(title)
   {
    case "Return":
          returnBooks();
          break;
  }

strings in switch are not supported in -source 1.6, use -source 7 or higher to enable strings in switch

So, I have already installed JDK7, Why compiler show this message and giving an error while on compiling?

I am using NetBeans

like image 449
Shahid Ghafoor Avatar asked Mar 21 '26 18:03

Shahid Ghafoor


1 Answers

I hate to say it, but: read the darn error message. It tells you exactly what the problem is.

You are compiling in Java 6 mode, not compiling in Java 7 mode. If you're using javac that comes with JDK 7, as the error message says, use the -source 7 flag:

> javac -source 7 {stuff here}
like image 104
Matt Ball Avatar answered Mar 24 '26 07:03

Matt Ball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!