2 ms·
Go doesn't have any closed or sealed types. An "enum" is just a subtype and subtypes can't restrict the range of their values. It's possible to have something l
by kbolino 2y ago
Go doesn't have any closed or sealed types. An "enum" is just a subtype and subtypes can't restrict the range of their values. It's possible to have something like a closed tagged union using an interface with an unexported method and type-switching, but the language won't understand this for e.g. detecting whether a switch without default is exhaustive.
There's also no way to declare a non-nil pointer nor to work cleanly with nested nil-able struct fields.
- pjmlp 2y agoGo's enums aren't even something to talk about when compared with classical Pascal enumerations. Naturally this is much better to type, type Weekdays int const ( Monday Weekdays = iota Tuesday Wednesday Thursday Friday Saturday Sunday ) than something like this, type Weekdays = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) /s