Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of strings in "switch" statement; Java SE 7

I wanted to use a String in a switch statement but I read that this feature was available from version java SE 7. I've downloaded it, when I type "java -version" in a console I read:

java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)

In my Eclipse project, I've modified the "JRE System Library" properties to "JavaSE'1.7".

After all this when I use a string on a switch statement I get an error: Cannot switch on a value of type string.

Any clue of what I'm missing?

Thanks!

like image 339
dedalo Avatar asked Apr 07 '26 06:04

dedalo


2 Answers

You need Eclipse Indigo 3.7.1 for Java 7 support - this was released at the end of September 2011.

like image 74
SteveD Avatar answered Apr 08 '26 18:04

SteveD


First off, you need the latest version of Eclipse (one that supports compiler compliance level of 1.7).

enter image description here

like image 39
adarshr Avatar answered Apr 08 '26 19:04

adarshr



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!