3 ms·
> fundamental containers like this really benefit from being type-safe Note that, at least in its current form, the native concurrent map type uses interface{}
by bascule 9y ago
> fundamental containers like this really benefit from being type-safe
Note that, at least in its current form, the native concurrent map type uses interface{} for all keys and values, and therefore offers no type safety:
https://github.com/golang/go/blob/master/src/sync/map.go https://github.com/golang/go/blob/master/src/sync/map.go
See also: https://github.com/golang/go/issues/18177 https://github.com/golang/go/issues/18177
All of Go's built-in pseudo-generic types (e.g. maps) require special support from the parser. I'm not sure if they plan on doing that for sync.Map as well, but this is clearly an area that could benefit from generics.