3

I'm on jre7 and I still can't switch on Strings. I installed jdk7 update 1 and pointed Eclipse to it but still no luck. Any idea what I'm doing wrong?

Here is a the code:

String code = "something"; switch(code) { case "xxx": dosomehting(); break; default: dosomethingelse(); break; } 

The error I get:

Cannot switch on a value of type String. Only convertible int values or enum constants are permitted.

3
  • Do you have an Eclipse version which supports Java SE 7? (e.g. version 3.7 should be fine AFAIK) Commented Oct 20, 2011 at 18:05
  • I'm on 3.7, that should be ok then. Commented Oct 20, 2011 at 18:52
  • 1
    You need Eclipse 3.7.1 for full Java 7 support. Commented Oct 21, 2011 at 9:39

3 Answers 3

2

I am pretty sure that Eclipse 3.7 only support jdk 1.6. You need 3.7.1 according to http://download.eclipse.org/eclipse/downloads/drops/R-3.7.1-201109091335/index.php

(Remember: Eclipse don't use suns compiler, they use their own, so installing jdk 1.7 is not enough).

Just open eclipse and select help->Check for updates. - That should upgrade you to 3.7.1

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

4 Comments

In the Properties -> Java Compiler the maximum level I get for Compiler Compliance level is 1.6. So that I guess seals it. How can I update Eclipse from 3.7 to 3.7.1 ?
I added a comment about upgrading from 3.7 to 3.7.1 - It was pretty easy for me.
Thanks Amnesyc, I know that this is an old thread but I just ran into this today on Eclipse 4.2.2 and looking at the compiler level fix my issue.
I am facing the same issue for Eclipse Kepler version i.e. 4.3.
1

It sounds like you're still trying to compile under the old JDK [6 or earlier] Install the JDK, and make sure your Eclipse settings reflect the new platform. Additionally check if your project is reflecting the JDK7 platform.

2 Comments

What I've done is change the buil path and make it point to the new jre that's in the jdk7. Now Eclipse shows JRE System Library [jdk1.7.0_01] in the build path. What else do I need to do? Is there some way to change the compiler being used?
If there is a way, try to get eclipse to run javac -version or the ilk as a post or pre compile step. I don't use eclipse so I can't give you exact details. However, Netbeans/IDEA use a "platform selection" [like VS] type interface to switch between the java platforms/versions
0

Three things spring to mind to check:

  • Make sure that Eclipse isn't still pointing to the old (6) install of the JDK.
  • Make sure that you haven't selected a lower source level for compilation; eg. -source 1.6.
  • Make sure you're using a version of Eclipse that supports Java 7 syntax.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.