FAQ
In addition, I recommend reading about how interfaces are implemented
internally, this helped me understand why things work the way they do and
it's easier to make a logical connection once you realize how it's
implemented:
http://research.swtch.com/interfaces

But I have to say that I still don't have a good logical grasp on what's
addressable and what's not and why, I just have to remember it for now or
let the compiler complain, think about it again and then fix it.

This is a good read too, the Map and Interfaces sections in particular (but
start at the top, don't just jump there):
https://github.com/golang/go/wiki/MethodSets

On Friday, August 28, 2015 at 12:31:55 AM UTC-7, Jesse McNelis wrote:

On Fri, Aug 28, 2015 at 3:50 PM, <gerald.r...@gmail.com <javascript:>>
wrote:
Yes, but that really isn't at the crux of the problem or the fix.

The strange looking thing is that by adding an '&' in the var
assignment,
sync.Locker in the method set Y suddenly accepts the structure X as
implementing Y independent of whether the embedded field sync.Mutex is
direct or pointer.

Requiring an embedded pointer field to satisfy the pointer-receiver
requirement of a method set member seems logically correlated. The
obliteration of that correlation by a distant var assignment (spooky action
at a distance) is, well, strange. Guessing it has something to do with the
heuristics of the type-inferencing system, but a guess is far shy of a
comfortable understanding.
There is no spooky at a distance action. The decision about whether a
type implements an interface is based on the type's method set.
http://golang.org/ref/spec#Method_sets

People often get confused about Method sets because of how the dot
selector will automatically take the address of receiver, so they
assume that T and *T both have the same method set.
http://golang.org/ref/spec#Selectors

The difference matter with interfaces because a value isn't
addressable while it's in an interface.
So if you want to call a method with a pointer receiver on a value in
an interface then the value must a pointer because the dot selector
can't just get you the address of that value.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 12 of 19 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 27, '15 at 10:48p
activeAug 29, '15 at 1:56a
posts19
users7
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase