0

以下 java 代码无法在 eclipse 中编译。我在这里做错了什么?如果该方法只返回一个int而不是一个,那么一切正常,enum所以它基本上设置好了。问题在于引入枚举返回类型。

public class myclass {
  public enum mytype {
      mytype2,
      mytype1,  
  };
  public static mytype retmytype() {
    return mytype2;
  }
}

//in another class
myclass.mytype t = myclass.retmytype(); //ERROR - myclass.mytype cannot be solved
4

1 回答 1

1

尝试替换return mytype2;return mytype.mytype2;

顺便说一句,您应该遵循 Java 命名约定;)

我认为您忘记了 main 方法(或程序流程中的任何其他调用方法)。尝试这个:

public class myclass {
  public enum mytype {
      mytype2,
      mytype1,  
  };
  public static mytype retmytype() {
    return mytype.mytype2;
  }
  public static void main(String[] args){
    myclass.mytype t = myclass.retmytype();
  }
}
于 2013-03-31T13:16:43.577 回答