File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes switch using strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "switch using strings" Watch "switch using strings" New topic

switch using strings

Tim Keune

Joined: Jul 31, 2013
Posts: 1
I'm using a switch structure with a string key. I get the following diagnostic:

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

I'm using NetBeans 7.3.1 with the SDK 1.7.

I'm a relative newbie for java so I don't know how to respond to the error message. I've searched far and wide and either found nothing or a gazillion irrelevant hits.
I'm so frustrated I'm ready to go sideways but that leaves the hole in my knowledge. I'd like to find out how to make this work. The prototype I'm working with is below. It handles responses to a menu selection (which will have dozens of choices.)

I'm hoping this forum is the resource I've been missing....
Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 970
Which version of Java do you want to use?

If 1.7, compile accordingly.

If 1.6, you have to rewrite the String-based switch into, say, a series of "equals" statements.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63868

Sounds like you've got the IDE configured to use Java 1.6.

I've copied this over to the IDEs forum for the Netbeans-savvy to help you out with proper configuration.

[Asking smart questions] [About Bear] [Books by Bear]
Peter Johnson

Joined: May 14, 2008
Posts: 5852

Look at the project properties and in the Libraries section make sure that your 1.7 JDK is selected.

JBoss In Action
I agree. Here's the link:
subject: switch using strings
It's not a secret anymore!