How to use Java enum type

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

How to use Java enum type
[Java] How to use Map
[Java] How to use Map
[Rails] How to use enum
How to use java Optional
[Rails] How to use enum
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
How to use Java HttpClient (Get)
How to use Java HttpClient (Post)
[Java] How to use join method
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
How to use Java enums (Enum) in MyBatis Mapper XML
Multilingual Locale in Java How to use Locale
[Java] How to use the File class
[Java] How to use the hasNext function
How to use submit method (Java Silver)
[Java] How to use the HashMap class
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to use the toString () method
Studying how to use the constructor (java)
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] How to use the Calendar class
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use java.util.logging
How to use map
How to use Twitter4J
How to use active_hash! !!
How to use hidden_field_tag
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
[Java] About enum type
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to type backslash \