Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

why enum could not be resolved in JAVA?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...