3

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!

2

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

enter image description here

Comments

0

Did you also go into the project properties in Eclipse and under Java Compiler pick the appropriate compiler compliance level?

Comments

0

You need to get latest version of eclipse. eclipse helios would be find for this.

3 Comments

I was trying it with Eclipse Helios. Finally I have downloaded Eclipse Indigo and it works
if you go with Eclipse Helios then it should be work. The problem is that you just need to select Java Compiler as 1.7 from Projecs Name -> Properties -> Java Compiler.
You're right, I've tried it and it works with both Eclipse versions, Helios and Indigo. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.