Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why enum could not be resolved in JAVA?

Tags:

java

enums

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?

like image 209
huahsin68 Avatar asked Jul 12 '26 21:07

huahsin68


2 Answers

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.

like image 185
stuhpa Avatar answered Jul 15 '26 09:07

stuhpa


  • the first compiles fine. Check your compiler level (should be at least 1.5)
  • inteRface
  • you cannot put code in the method body, as you did in ClassC. It should be in a method or in a block
like image 36
Bozho Avatar answered Jul 15 '26 10:07

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!