You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
my question is: why does go not seem to care that you pass the correct type (pointer or not) into a method?
Specifically, at the end you have a code block:
func main() {
m := &Mutatable{0, 0} // line * below seems to work even without the & here
fmt.Println(m)
m.StayTheSame()
fmt.Println(m)
m.Mutate() . //*
fmt.Println(m)
}
however, if you just did m := Mutatable{0, 0}, then m.Mutate() still works. Why? What is the effect of this? Why doesn't the compiler complain about m not being a pointer?
The text was updated successfully, but these errors were encountered:
I found your post here: https://nathanleclaire.com/blog/2014/08/09/dont-get-bitten-by-pointer-vs-non-pointer-method-receivers-in-golang/
after reading this page: https://gobyexample.com/methods
my question is: why does go not seem to care that you pass the correct type (pointer or not) into a method?
Specifically, at the end you have a code block:
however, if you just did
m := Mutatable{0, 0}
, thenm.Mutate()
still works. Why? What is the effect of this? Why doesn't the compiler complain about m not being a pointer?The text was updated successfully, but these errors were encountered: