|
|
|
|
|
by coder543
2178 days ago
|
|
It is type safe. Any integers with a defined type cannot be used as values of type "state" without an explicit conversion occurring. Type safety does not guarantee exhaustive matching, unfortunately, because the underlying type is still an integer, but that's a separate issue. https://play.golang.org/p/K0m4hfmw8C1 I wish Go had proper, exhaustive enums too (sum types preferably), but you're incorrect when you say that they don't have type safety. |
|
However, they are not enums in any way either, since there is no limit on their possible values to some restricted set - they really are just integers, even more than in C# or C++, even though there is no implicit conversion.