Enums
An enum
is a type that consist of a fixed list of named constants. The enum
keyword is used to define an enumeration type.
Defining an Enum
An enum
can not be defined inside a method since its a type just like a class. An enum
can be defined inside a class, interface or in its own file name.
public enum MessageType {
CHAT,
VIDEO,
PICTURE,
TEXT,
NOTIFICATION
}
Using the Enum
MessageType
can take any one of the valid constants of CHAT
, VIDEO
, PICTURE
, TEXT
or NOTIFICATION
.
public class Main {
public static void main(String[] args) {
MessageType messageType = MessageType.CHAT;
}
}