4 ms·
Like an enum, a union have a closed set of elements so it can be statically checked all cases are handled. With an interface, someone could add a new implement
by bazoom42 2y ago
Like an enum, a union have a closed set of elements so it can be statically checked all cases are handled.
With an interface, someone could add a new implementation, causing codee to fail at runtime.