sync.waitgroup:
https://golang.org/src/sync/waitgroup.go?s=2022:2057#L43
Why does the (T *WaitGroup) receiver not throw an error when I call it on a non-pointer type (T WaitGroup) ?
As a rule of thumb, I personally use a pointer reciver in case I want to mutate something inside the struct. And non pointer in case I don't want to
Thanks, I have been doing this too. I got confused earlier with ‘pointer/non pointer’ consideration with interfaces vs their general reference use. I have replicated a few examples and now understand this nuance much better.
https://play.golang.org/p/4IQzUJyw0_o a pointer-reciver just takes the pointer of the variable you're calling it on+
Thank you, I understand that. I'm going to send a playground link in a bit of what actually got me confused.
https://play.golang.org/p/YdinlQBN_0E For a moment, I mixed up subtle differences between interface and concrete types, in the context of a method receiver. (Refer to line 31 and 28. ) I mistook that for a non-pointer type, I could not call its pointer receiver (as with type interface). I know better now but please do correct me if you notice gap in my understanding. Thanks!
Обсуждают сегодня