0

I know that 'switch' on strings was not workable before java 7 and was implemented only in java 7 and later. But I am using java 8 and I still get the error message "cannot switch on strings". Can anyone explain why and how do I get around it?

tech_logman
  • 109
  • 2
  • 2
  • 8

1 Answers1

1

Even if you are using JDK 8 it's possible that you are not using the java 8 compiler compliance level .

If you are on eclipse, you can set the compiler level like this:

enter image description here

STaefi
  • 4,297
  • 1
  • 25
  • 43
  • no wait .. in helios compliance level is already set to '1.7' but i still get the error... wonder why? – tech_logman May 21 '18 at 05:31
  • Maybe you need to clean and Build again. Use project menu, select clean then select your project. Make sure `Build Automatically` is checked under `Project` menu. – STaefi May 21 '18 at 05:34
  • It's somehow wired. I can't really remember eclipse helios supports the JDK 8 or not. May be that's why it is not working. Maybe downloading a newer version of eclipse like Luna, Neon or Oxygen solve the problem. I'm on Luna and it's OK. – STaefi May 21 '18 at 05:47
  • To make sure that you are using the right JDK and path configurations on eclipse follow the steps I visually illustrated in the following answer: https://stackoverflow.com/questions/50245741/how-to-see-the-source-code-for-java-sdk-java-lang-java-util-classes-in-e/50245928#50245928 This answer is about setting JDK instead of JRE to the project to see the source codes of the JDK, but the steps should help you to see if you are using the right JDK on your project or not. – STaefi May 21 '18 at 05:56
  • true , the issue was resolved in Oxygen which i already have installed and compliance level was set to 1.8 . But it somehow does persist in helios even after the compliance level is set to 1.7 (rechecked for version and compliance). Also tried it on terminal with java version 8, and i get the result right. So i think it is an eclipse issue. – tech_logman May 21 '18 at 06:00