4 ms·
Yes, the only downside I see is that if you do: type Number interface { int | int64 | int32 } var n Number The default value for n has to be nil, rath
by earthboundkid 5y ago
Yes, the only downside I see is that if you do:
type Number interface { int | int64 | int32 }
var n Number
The default value for n has to be nil, rather than 0, because Go can't choose between the types (int 0, int64 0, etc.). And of course, you can't do n + x (assuming x is also a Number) because x might be a different kind of number. Still, it's a pretty good simplification from the current restrictions, and it builds well on existing concepts.