|
|
|
|
|
by lederhosen
2852 days ago
|
|
You can not have a custom collection class containing objects _only_ of a certain type. For example ConcurrentHashTable<Int, String>. That is something that is used every single day. It is used so frequently that Go has generic slice and map built into the language. That is, they created a language with lots of special datatypes that can not be created in normal Go because of its lack of generics instead of creating generics. It is a bit like asking a Java-programmer to use Java 1.4. When you ask a Java programmer, or C# programmer or Haskell programmer or Swift programmer or... what they would change in the language you do not get the answer: remove generics. |
|
Go generate is like a manual step for having generics, I imagine one day soon its functionality or something similar will be part of go build.
In response to your particular example, a map plus a mutex seems sufficient.
I dig that it's a few extra lines of code, but I guess I'm looking for a really mean example.