IntelliJ switch 语句使用字符串错误:使用 -source 7

我正在尝试使用 IntelliJ(在 Mac OS X 上)编译我使用 Eclipse 编写的一些代码.我尝试运行以下代码:

I'm trying to use IntelliJ (on Mac OS X) to compile some code I wrote using Eclipse. I've attempted to run the following code:

switch (category) {
    case "below 20":
        below20++;
        break;
    case "20 to 29":
        to30++;
        break;
    case "30 to 39":
        to40++;
        break;
    case "40 to 49":
        to50++;
        break;
    case "50 to 59":
        to60++;
        break;
    case "60 to 69":
        to70++;
        break;
    case "70 t0 79":
        to80++;
        break;
    case "80 to 89":
        to90++;
        break;
    case "90 to 99":
        above90++;
        break;
    default:
        break;
}

但是,我得到了错误:

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

我知道一些答案将是:RTFE(即用错误替换手动).但我做到了.我尝试了以下方法:

I know that some of the answers will be: RTFE (i.e. replace Manual with Error). But I did. I've attempted the following:

  • Preferences > Compiler > Java Compiler 并将 -source 7 和/或 -target 1.7 添加到 Additional command line parameters
  • Edit Configurations:勾选Use Alternative JDK并写入目录/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
  • Preferences > Compiler > Java Compiler and added -source 7 and/or -target 1.7 to Additional command line parameters
  • Edit Configurations: checked Use Alternative JDK and wrote in the directory /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home

它还没有修复它.我做错了什么?

And it hasn't fixed it. What am I doing wrong?

注意:我知道这很明显,因为目录在上面,但是我确实安装了 Java 7.

Note: I know this is obvious because the directory is above, but I do have Java 7 installed.

提前致谢!

推荐答案

在 Intellij IDEA 你也应该去 Project Settings -> Project 并设置适当的 项目语言级别那里

At the Intellij IDEA you should also go to Project Settings -> Project and set appropriate Project language level there

相关文章