Enum of Java
public enum TaskType {
PRIVATE, WORK
}
import java.util.UUID;
public class Task {
private String id;
private TaskType type;
private String body;
public Task(TaskType type, String body) {
this.id = UUID.randomUUID().toString();
this.type = type;
this.body = body;
}
public String getId() {
return id;
}
public TaskType getType() {
return type;
}
public void setType(TaskType type) {
this.type = type;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public static void main(String[] args) {
Task task = new Task(TaskType.PRIVATE, "buy milk");
TaskType type = task.getType();
System.out.println(TaskType.PRIVATE.equals(type)); // => true
switch(type) {
case PRIVATE:
System.out.println("Task[type = " + type + "]");
break;
case WORK:
System.out.println("Task[type = " + type + "]");
break;
}
}
}
public enum HttpStatus {
OK(200), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500);
private final int value;
private HttpStatus(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static void main(String[] args) {
HttpStatus hs = HttpStatus.OK;
System.out.println("HttpStatus = " + hs + "[" + hs.getValue() + "]");
}
}