无法在 JRE7 中打开字符串
我使用的是 jre7,但仍然无法打开 Strings。我安装了 jdk7 update 1 并将 Eclipse 指向它,但仍然没有成功。知道我做错了什么吗?
这是代码:
String code = "something";
switch(code) {
case "xxx": dosomehting(); break;
default: dosomethingelse(); break;
}
我得到的错误:
无法打开字符串类型的值。仅允许使用可转换的 int 值或枚举常量。
I'm on jre7 and I still can't switch on Strings. I installed jdk7 update 1 and pointed Eclipse to it but still no luck. Any idea what I'm doing wrong?
Here is a the code:
String code = "something";
switch(code) {
case "xxx": dosomehting(); break;
default: dosomethingelse(); break;
}
The error I get:
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很确定Eclipse 3.7只支持jdk 1.6。你需要3.7.1根据
http://download.eclipse.org/eclipse /downloads/drops/R-3.7.1-201109091335/index.php
(记住:Eclipse不使用suns编译器,他们使用自己的编译器,所以安装jdk 1.7 还不够)。
只需打开 eclipse 并选择帮助->检查更新。 - 这应该将您升级到 3.7.1
I am pretty sure that Eclipse 3.7 only support jdk 1.6. You need 3.7.1 according to
http://download.eclipse.org/eclipse/downloads/drops/R-3.7.1-201109091335/index.php
(Remember: Eclipse don't use suns compiler, they use their own, so installing jdk 1.7 is not enough).
Just open eclipse and select help->Check for updates. - That should upgrade you to 3.7.1
听起来您仍在尝试在旧的 JDK [6 或更早版本]下进行编译。安装 JDK,并确保您的 Eclipse 设置反映新平台。另外检查您的项目是否反映 JDK7 平台。
It sounds like you're still trying to compile under the old JDK [6 or earlier] Install the JDK, and make sure your Eclipse settings reflect the new platform. Additionally check if your project is reflecting the JDK7 platform.
我想到了需要检查的三件事:
Three things spring to mind to check: