Is is possible to write a anonymous enum class and then comparing what it contains? Eg.
enum class { APPLE, BANANA } fruitType;
// ...
if (fruitType == fruitType::APPLE)
// ...
An anonymous Enum is an unnamed enum.
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). To create an enum , use the enum keyword (instead of class or interface), and separate the constants with a comma.
An enumeration is a user-defined type that consists of a set of named integral constants that are known as enumerators. Note. This article covers the ISO Standard C++ Language enum type and the scoped (or strongly-typed) enum class type which is introduced in C++11.
Kotlin enums are classes, which means that they can have one or more constructors. Thus, you can initialize enum constants by passing the values required to one of the valid constructors. This is possible because enum constants are nothing other than instances of the enum class itself.
No, fruitType
is a variable (despite Type in the name). You cannot use a variable name to access things about its type.
The idea with enum class
is that the values are not visible outside the definition unless you prefix them with the type name. If the type doesn't have a name, this will be difficult!
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