why enum could not be resolved in JAVA?

前端 未结 4 1413
忘掉有多难
忘掉有多难 2020-12-21 16:05

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

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

public i         


        
相关标签:
4条回答
  • 2020-12-21 16:41

    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.

    0 讨论(0)
  • 2020-12-21 16:45

    You mistyped inteface for interface.

    Maybe your compiler is too old, so that it doesn't know that enum is a keyword.

    0 讨论(0)
  • 2020-12-21 16:49
    • 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
    0 讨论(0)
  • 2020-12-21 17:03

    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.

    0 讨论(0)
提交回复
热议问题