On Saturday, July 16, 2016 at 10:13:51 PM UTC+8, adon...@google.com wrote: > > On Saturday, 16 July 2016 05:31:41 UTC-4, Jan Mercl wrote: >> >> On Sat, Jul 16, 2016 at 10:39 AM T L <tapi...@gmail.com> wrote: >> >> > I know this result, but I just need the reason, not the result. >> >> The method set distinction of T vs *T allows to forbid calling methods >> intended to mutate the receiver (ie. receiver is *T) on the wrong receiver >> type (T). The later case would mutate the value (not the value that >> should be pointed to) stored _in_ the interface, not the value at the >> caller's site. Declaring the method receiver as *T forces callers to use >> the properly typed thing (*T instead T) they pass via interfaces as the >> compiler will reject the incorrect case. >> > > Here's another way to think about it: the methods of T are the methods > appropriate for any *value* of type T. The methods of *T are the methods > appropriate for a *variable* of type T (the variable pointed to by the *T > pointer). The methods of *T can read the value of the variable, but they > can also update it. So you can do more with a variable than a > (non-addressable) value, and that's why *T has more methods than T. >
Reasonable, yes, some values are not addressable. -- 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. For more options, visit https://groups.google.com/d/optout.