4 ms·
What about maps? Non-nil maps sure seem like they're "reference types", look at [0]. [0] https://play.golang.org/p/xtY_ASExQzR https://play.golang.org/p/xtY_AS
by Joker_vD 5y ago
What about maps? Non-nil maps sure seem like they're "reference types", look at [0].
[0] https://play.golang.org/p/xtY_ASExQzR https://play.golang.org/p/xtY_ASExQzR
- masklinn 5y ago"reference types" is a very specific concept from a specific category of languages: types which are always heap-allocated and sitting behind an invisible (and un-interactible) pointer. But Go doesn't have that distinction, and has actual pointers you can use directly. A map is just a heap-allocated structure sitting behind a pointer. If you create a type which is a pointer to a struct, sure you can say you've built a reference type if you want, but that doesn't actually say much to anyone, because that's not a distinction the language makes, unlike Java or C#.
- Joker_vD 5y ago> types which are always heap-allocated and sitting behind an invisible (and un-interactible) pointer > A map is just a heap-allocated structure sitting behind a pointer. And the difference is?.. Because maps in Go behave exactly as if they were un-referenceable pointers to the hidden, heap-allocated hashtables.