3 ms·
Go actually has enums in the basic way that you're thinking of them, but they're just constants of a custom type based on int. So you'd define `type Suit int`
by roncesvalles 2y ago
Go actually has enums in the basic way that you're thinking of them, but they're just constants of a custom type based on int.
So you'd define `type Suit int` and have constants of type Suit that are `const DIAMONDS Suit = 0` ... `const SPADES Suit = 3`.
Go just doesn't have first-class enums with cardinality less than an int, like Java would. Which means you could have a Suit type variable with a value of 4 or 9000, because Suit serializes/deserializes as an int, not some custom string representation as in other languages.