Are maps passed by value or by reference in Go?

前端 未结 3 1803
北恋
北恋 2021-01-30 05:10

Are maps passed by value or reference in Go ?

It is always possible to define a function as following, but is this an overkill ?

func foo(dat *map[string         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 05:22

    In this thread you will find your answer :

    Golang: Accessing a map using its reference

    You don't need to use a pointer with a map.

    Map types are reference types, like pointers or slices[1]

    If you needed to change the Session you could use a pointer:

    map[string]*Session
    

    https://blog.golang.org/go-maps-in-action

提交回复
热议问题