[英]VSC Cannot switch on a value of type String for source level below 1.7
I have an error in my code because I am using a String like a Switch case: 我的代码中有错误,因为我使用的是类似Switch的String:
private static void setNumberValues(Employee emp, Address address,
String keyName, long value, List<Long> phoneNums) {
switch(keyName){
case "zipcode":
address.setZipcode((int)value);
break;
case "id":
emp.setId((int) value);
break;
case "phoneNumbers":
phoneNums.add(value);
break;
default:
System.out.println("Unknown element with key="+keyName);
}
}
I am facing this error in Visual Studio Code with the Red Hat Java extension. 我在带有Red Hat Java扩展的Visual Studio Code中遇到此错误。
I know what the error means so, here is my environment: 我知道该错误意味着什么,这是我的环境:
My jdk version: 我的JDK版本:
/usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
My Visual Studio Code java.home settings: 我的Visual Studio Code java.home设置:
"java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home"
How to tell VSC to compile with my jdk 1.8 and don't bother with old java 1.6 ? 如何告诉VSC使用我的jdk 1.8进行编译,而不必使用旧的Java 1.6?
Regards, 问候,
S. S.
ok thanks for the suggestions, I read the thread as suggested by @Stephen-c but actually this doesn't solve my problem. 好的,谢谢你的建议,我按照@ Stephen-c的建议阅读了线程,但这实际上并不能解决我的问题。 I change the POM like this: 我这样更改POM:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
But in Visual Studio Code I still have the keyName underlined in red and the error: 但是在Visual Studio Code中,我仍然用红色下划线标出了keyName和错误:
[Java] Cannot switch on a value of type String for source level below 1.7.
Only convertible int values or enum variables are permitted
String keyName - com.journaldev.json.EmployeeJSONParser.setNumberValues(Employee, Address, String, long, List<Long>)
Thanks, 谢谢,
S. S.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.