加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java 7切换语句,字符串不起作用

发布时间:2020-12-14 17:46:39 所属栏目:Java 来源:网络整理
导读:根据 The Java Tutorials,在 Java SE 7和更高版本中,您可以在switch语句的表达式中使用String对象. String s = ...switch(s){ //do stuff} 但这是真的吗?我已经安装了JRE并将其添加到Eclipse项目的构建路径,但是我收到以下编译时错误: Cannot switch on a
根据 The Java Tutorials,在 Java SE 7和更高版本中,您可以在switch语句的表达式中使用String对象.
String s = ...
switch(s){
    //do stuff
}

但这是真的吗?我已经安装了JRE并将其添加到Eclipse项目的构建路径,但是我收到以下编译时错误:

Cannot switch on a value of type
String. Only convertible int values or
enum constants are permitted

此外,我想我已经配置正确,因为我可以使用其java.nio.file.Files类以及JLayer.

有任何想法吗?

解决方法

虽然JDT团队确实实施了 Switch on String feature,但对Java 7的支持不会在Eclipse 3.7.1之前:

见bug 288548:

Due to late availability of JSR-292 (Invoke Dynamic) and JSR-334 (Project Coin)
and due to the official release date (July 28,2011) of Java 7 being after 3.7
ships we had to defer the Java 7 support to 3.7.1. It has not yet been decided
whether this will be available as part of the 3.7.1 downloads or as separate
feature update.

The work for the Java 7 features is currently in progress in the ‘BETA_JAVA7’ branch and we will deliver separate updates for the stable builds in order to provide early access to the Java 7 features for interested parties.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读