简体   繁体   English

有JDK和JRE8但仍然不能使用带字符串的开关

[英]Have JDK and JRE8 but still can't use switch with strings

Switch statements with strings were introduced in JDK 7 and I have JDK 8 and JRE 8 but when I attempt to use a switch statement with strings I get the following error: 带有字符串的switch语句在JDK 7中引入,我有JDK 8和JRE 8,但是当我尝试使用带有字符串的switch语句时,我得到以下错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 线程“main”中的异常java.lang.Error:未解决的编译问题:

Cannot switch on a value of type String for source level below 1.7. 如果源级别低于1.7,则无法为String类型的值打开。 Only convertible int values or enum variables are permitted 只允许使用可转换的int值或枚举变量

What should I do? 我该怎么办?

Which IDE are u using? 你使用哪个IDE? I just give you some hint for Eclipse. 我只是给你一些Eclipse的提示。 Right click your project and found properties, switch to Java Compiler tab, make sure the compilation level is set to java 7 or above. 右键单击项目并找到属性,切换到Java Compiler选项卡,确保编译级别设置为java 7或更高版本。 I hope you are not using some last decade Eclipse because compilation level is bound to the Eclipse you use, not the JDK. 我希望你没有使用过去十年的Eclipse,因为编译级别绑定到你使用的Eclipse,而不是JDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM