使用字符串错误的IntelliJ switch语句:使用-source 7 [英] IntelliJ switch statement using Strings error: use -source 7

查看:561
本文介绍了使用字符串错误的IntelliJ switch语句:使用-source 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  switch(category){
case20以下:
低于20 ++;
休息;
案例20至29:
至30 ++;
休息;
案例30至39:
至40 ++;
休息;
case40 to 49:
to50 ++;
休息;
案例50至59:
至60 ++;
休息;
case60 to 69:
to70 ++;
休息;
case70 t0 79:
to80 ++;
休息;
case80 to 89:
to90 ++;
休息;
case90 to 99:
高于90 ++;
休息;
默认值:
break;
}

然而,我收到错误:

  java:-source 1.6 
不支持switch中的字符串(使用-source 7或更高版本来启用switch中的字符串)

我知道有些答案是:RTFE(即用Error替换Manual)。但我做到了。我尝试过以下方法:




  • 首选项>编译器> Java编译器并添加 -source 7 和/或 -target 1.7 其他命令行参数

  • 编辑配置:选中使用替代JDK 并在目录中写入 /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home



并没有修复它。我做错了什么?



注意:我知道这很明显,因为目录在上面,但我安装了Java 7 。 / p>

提前致谢!

解决方案

在Intellij IDEA,您还应该转到项目设置 - > 项目并设置相应的项目语言级别那里


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;
}

However, I get the error:

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

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 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?

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

Thanks in advance!

解决方案

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

这篇关于使用字符串错误的IntelliJ switch语句:使用-source 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆