What's the point of using : int in the enum declaration as following?
public enum AAType : int
{
Folder = 0,
File = 1,
Link = 2
}
There are a very small number of places where using int flags is still preferable in modern Java code, but in most cases you should prefer to use an enum , due to the type safety and expressiveness that they offer.
No, we can have only strings as elements in an enumeration.
Enumerations are integers, except when they're not - Embedded.com.
The advantages of using enums are that they are very easy to use and represented as strings but processed as integers. Enums are easy to maintain and improve code readability because they provide symbolic named constants, which means you need to remember the names, not the integer values.
The default underlying type of an enum
is int
, so by specifying it explicitly you only (perhaps) gain in clarity, but the behavior's just the same as if : int
was omitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With