On Tue, Mar 14, 2023 at 7:07 PM Frank Jüdes <jued...@gmail.com> wrote:
> Thank you very much Ian! > I am using a pointer to the map because i want to pass the map by > reference, not by value. > Those maps can become pretty large and are being handed down through a > couple of function calls and i don't want them to be copied over and over > again. > Maps are a special-case. You can't pass them "by value" in the sense you mean because a "map" value is a very tiny structure that contains a pointer to the actual map. Possibly the oldest public discussion of the fact maps are reference type is this blog post: https://go.dev/blog/maps. Using a pointer does, in fact, avoid copying that very small data structure but is not necessary to keep from copying the entire map. > I read the document you referenced, but am not able to understand… > So i can use interface{} or any just to generalize simple types? > Why is the compiler accepting then a p_Values map[string]interface{} as a > parameter of a function? - What would be a compatible data-type to pass as > this parameter? > The compiler accepts a type of "map[string]interface{}" because that is well defined and obviously useful, Functions, such as those in the fmt package, would not be useful if a function could not deal with the "interface{}" type directly or indirectly. Your confusion is very common and arises from the misconception that the Go map implementation will magically convert map values from a concrete type (e.g., "int") to the "any" type if that is what is needed in a particular context. One reason it doesn't do so is the same reason it doesn't auto-magically convert any other map value type; e.g., "int" to "float". -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD8eKMBwJgQ_Qvn163mZz3%3D4tZ18Lpugp5fO_M1hSj68RA%40mail.gmail.com.