简体   繁体   English

VSC无法为低于1.7的源级别打开String类型的值

[英]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.

相关问题 eclipse错误,“无法为低于1.7的源级别打开String类型的值” - eclipse error, “Cannot switch on a value of type String for source level below 1.7” 使用Eclipse的Android项目给出错误:源级别低于1.7时无法打开String类型的值 - Android project using Eclipse gives error: Cannot switch on a value of type String for source level below 1.7 “无法为低于 .. 的源级别打开字符串类型的值” Eclipse 中的错误 - “Cannot switch on a value of type String for source level below ..” error in Eclipse eclipse中的openjdk 1.7:不允许运算符的源级别低于1.7 - openjdk 1.7 in eclipse: operator is not allowed for source level below 1.7 如何修复&#39;&lt;&gt;&#39;运算符不允许源级别低于1.7的1.6? - How to fix '<>' operator is not allowed for source level below 1.7 in 1.6? 如何解决“对于低于1.7的源级别,此处不允许的资源规范”? - How to fix “Resource specification not allowed here for source level below 1.7”? 低于1.7的源代码级别不允许使用Jboss jsp问题&lt;&gt;运算符 - Jboss jsp issue <> operator is not allowed for source level below 1.7 低于1.7的源代码级别不允许使用资源规范 - Resource specification not allowed here for source level below 1.7 对于低于 1.7 的源级别,此处不允许使用资源规范 - Resource specification not allowed here for source level below 1.7 无法将 Java 源级别更改为 Eclipse 中的 1.7 与 Maven - Cannot change Java source level to 1.7 in Eclipse with Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM