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 7and/or-target 1.7to 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
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
