2 ms·
Are they adding Java style generics (type erasure), or C++ style (compile time specialization)?
by hedora 6y ago
Are they adding Java style generics (type erasure), or C++ style (compile time specialization)?
- skybrian 6y agoAs I understand it, the language spec is designed so that compile-time specialization is possible but not required. It could be some mixture of both.
- mappu 6y agoThe go2 proposal (as currently implemented) is a source-to-source translator back to go1, so neither in that case. As for the existing implementation of generic map[K]V, generic []T, chan(T), etc., it's a best-of-both-worlds mix - a kind of erasure (there is only one map implementation in a Go binary) but with a static vtable for accessors without Java's need for boxing - all possible owing to the clever coupling between the runtime and the compiler. See https://dave.cheney.net/2018/05/29/how-the-go-runtime-implements-maps-efficiently-without-generics https://dave.cheney.net/2018/05/29/how-the-go-runtime-implem...