Reputation: 6979
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?
Upvotes: 2
Views: 22972
Reputation: 115328
You must write code either in a method or in a static
block (assigning static values). Your System.out.println()
is written into a class
. Create method and put System.out.println()
there.
Upvotes: 0
Reputation: 306
I had a similar problem:
enum can't be resolved to a type
Eclipse offered to import Enum
instead.
I went to
Compatible JREs
pane. After rebuild enum
was recognized properly.
Upvotes: 10
Reputation: 597046
inteRface
ClassC
. It should be in a method or in a blockUpvotes: 6
Reputation: 41617
You mistyped inteface
for interface
.
Maybe your compiler is too old, so that it doesn't know that enum
is a keyword.
Upvotes: 0