我在这里试图在类对象中获取和设置一个枚举,但不知道该怎么做。这就是我到目前为止所拥有的。我已经查阅了所有可能的例子,有些例子似乎太复杂了,我无法理解。请问有什么帮助吗?
public class EnumExample {
public static class Task {
private String _task;
public enum Priority {
ZERO (0), MAYBE (1), LOW (2), MEDIUM (3), HIGH (4), EXTREME (5);
private int _priority;
Priority() {
_priority = 0;
// Does this set set the default priority level to 0??
}
Priority(int priority) {
_priority = priority;
// This is where I can set the priority level of this task??
}
public int getPriority() {
return _priority;
}
public void setPriority(int priority) {
_priority = priority;
}
}
}
public static void main(String[] args) {
Task task = new Task();
task._task = "Study for test";
System.out.println(task._task);
System.out.println(task.getPriority());
// How do I set the priority level for task "study for test"??
// task.Priority = task.Priority.EXTREME;
// How do I retrieve the value of priority??
// System.out.println(task._task.getPriority());
}
}