The "Effective Go" documentation says the following.
The rule about pointers vs. values for receivers is that value methods can be invoked on pointers and values, but pointer methods can only be invoked on pointers.
http://tip.golang.org/doc/effective_go.html#pointers_vs_values
As such, if I define a method like the following, wouldn't it not be callable with a value?
func (self *someStruct) Change(newNum int) {
self.propertyOne = newNum
}
However, the following still seems to work.
structInstance := &someStruct{
propertyOne: 41,
}
(*structInstance).Change(456)
Why?
Is it converting the value (*structInstance)
back into an address/pointer for the Change
call?
How do I ensure that some instance of a type cannot call a method defined on the pointer (like Change
)?