[英]Can't switch to compiler compliance level 1.8 in Eclipse Helios
I am pretty new to eclipse and programming,Currently i am trying to learn java from a tutorial from caveofprogramming.com When i was trying to follow one tutorial based on switch an error keep disturbing me. 我是eclipse和编程的新手,目前我正在尝试从caveofprogramming.com的教程中学习java当我试图按照一个基于开关的教程时,一个错误让我感到不安。
import java.util.Scanner;
public class App{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("enter a number");
String text = input.nextLine();
switch(text) {
case "start";
System.out.println("Machine started");
break; } } }
And it gives me an error on the switch command saying: 它给我一个错误的switch命令说:
cannot switch on a value of type string.
无法打开字符串类型的值。 only int values or enum constants are permitted
只允许使用int值或枚举常量
John Purcell at caveofprogramming.com suggested that its because of the compiler compliance level which is currently 1.4 and he said me to switch that to 1.8 but its not available there.1.6 is the last level which i can use. caveofprogramming.com的 John Purcell建议,因为编译器合规级别目前为1.4,他说我将其切换到1.8但是它不可用.1.6是我可以使用的最后一级。
Download and install the current Eclipse version . 下载并安装当前的Eclipse版本 。 Eclipse has a build-in Java compiler.
Eclipse有一个内置的Java编译器。 Switching on
String
s was added in Java SE 1.7. 在Java SE 1.7中添加了开启
String
。 Java SE 1.4 is a very old version of Java. Java SE 1.4是Java的一个非常古老的版本。 It's not a good idea to learn programming using a version of Java which is that old.
使用旧版本的Java学习编程并不是一个好主意。
Also, as the other answer suggests, install the latest JDK. 另外,正如另一个答案所示,安装最新的JDK。
Your friend is correct in saying that it is because of a compiler compliance level. 你的朋友说这是因为编译器合规性水平是正确的。 In order to be able to fix your problem, your compiler must be version 1.7 or 1.8.
为了能够解决您的问题,您的编译器必须是版本1.7或1.8。 If you're using an IDE, you'll need to download a JDK to match up to whichever version you need (would recommend 1.8 as it's not EOL'd).
如果您正在使用IDE,则需要下载JDK以匹配您需要的任何版本(建议使用1.8,因为它不是EOL)。 If you're using Maven, you can change your compiler level by using the Maven Compiler Plugin .
如果您正在使用Maven,则可以使用Maven编译器插件更改编译器级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.