This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "switch using strings" Watch "switch using strings" New topic
Author

switch using strings

Tim Keune
Greenhorn

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
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
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
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

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: http://aspose.com/file-tools
 
subject: switch using strings
 
Similar Threads
Local Variable inside Switch
Accessing data source inside Action servlet
Parsing Commands from String Input
Switch abuse?
Switch statement