为什么枚举在JAVA中无法解决? [英] why enum could not be resolved in JAVA?

查看:331
本文介绍了为什么枚举在JAVA中无法解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用J2EE Eclipse Indigo,我有三个类声明如下:

  public interface ClassA {
public static enum TYPE {TYPE1,TYPE2};
}

public interface ClassB扩展ClassA {

}

public class ClassC实现ClassB {
System.out。的println(TYPE.TYPE1);
}

ClassC中的TYPE上有一个编译错误。它抱怨枚举不能解决一个类型。还有一个在ClassA中枚举的警告,它抱怨说:

 此行上的多个标记
- 'enum'不应该用作标识符,因为它是
上的源级别1.5的保留关键字 - 枚举不能解析为类型
- 语法错误,插入;完成FieldDeclaration

我可以知道这段代码中的错误是什么?

解决方案

我有一个类似的问题:


枚举不能解决一个类型


Eclipse提供导入枚举 p>

我去了




  • 首选项 - > Java-> Installed_JREs-> Execution_environment;

  • 在执行环境窗格中选择JavaSE-1.6;和

  • 兼容JREs 窗格中选中jre6。



重建后枚举被正确识别。


I was using J2EE Eclipse Indigo, and I have three class declare like this:

public interface ClassA {
   public static enum TYPE { TYPE1, TYPE2 };
}

public interface ClassB extends ClassA {

}

public class ClassC implements ClassB {
   System.out.println(TYPE.TYPE1);
}

There was a compilation error on TYPE in ClassC. It complain that "enum cannot be resolved to a type". And also a warning for enum in ClassA, it complain that:

Multiple markers at this line
 - 'enum' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on
 - enum cannot be resolved to a type
 - Syntax error, insert ";" to complete FieldDeclaration

May I know what cause the error in this code?

解决方案

I had a similar problem:

enum can't be resolved to a type

Eclipse offered to import Enum instead.

I went to

  • Preferences->Java->Installed_JREs->Execution_environment;
  • Selected JavaSE-1.6 in "Execution Environments" pane; and
  • Checked jre6 in Compatible JREs pane.

After rebuild enum was recognized properly.

这篇关于为什么枚举在JAVA中无法解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆