以下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
最佳答案
尝试将return mytype2;
替换为return mytype.mytype2;
顺便说一句,您应该遵循Java命名约定;)
我认为您忘记了主要方法(或程序流程中的任何其他所谓的方法)。
尝试这个:
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();
}
}