IntelliJ switch statement using Strings error: use -source 7(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
这篇关于IntelliJ switch 语句使用字符串错误:使用 -source 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:IntelliJ switch 语句使用字符串错误:使用 -source 7


基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01