An enumeration type is a data type that you can create yourself like a class, and it is a collection of constants.
enum Result {
SUCCESS,
ERROR,
}
public class Test {
public static void main(String[] args) {
Result res;
res = Result.SUCCESS;
switch(res) {
case SUCCESS:
System.out.println("OK!");
System.out.println(res.ordinal());
break;
case ERROR:
System.out.println("NG!");
System.out.println(res.ordinal());
break;
}
}
}
Recommended Posts