Like any other language, Java has the enum
feature that allows us to enumerate items. It is helpful to list delimited items in your code, such as the seasons. Regarding the readability of code, it is better and cleaner than using constant codes such as int
. It avoids mistakes, such as an invalid number or a value the system does not support. Once we're talking about any number type such as int
, float
, double
, or long
, enum
can support any value. On the other hand, with an enum
, the API only has valid values.
The question is: Can we do more with enum
? Where else can we use an enum
? In this article, discover tips that are excellent and effective in Java.