This is the error message I am getting:
cannot use c.ReceiverChans (type []chan *Message) as type []chan interface {} in function argument
This is the error message I am getting:
cannot use c.ReceiverChans (type []chan *Message) as type []chan interface {} in function argument
The types are different. A *Message
implements the empty interface, but that doesn't mean you can take a slice or chan of *Message
and pass it to something that expects a slice or chan of interfaces.
The way I think of interfaces as a particular data structure; a pair of a pointer to a value and a pointer to the underlying type. It's not exactly how interfaces work, but it helps my intuition. Using this intuition, if I pass an int, say, to a function that wants an interface{}
, I imagine my value getting wrapped inside this interface pair implicitly by the compiler before the function's called. If instead, the function expects a []interface{}
, and I want to pass a []int
, what can the compiler do? It would have to construct a new array of the interface pairs, but then (a) that'd be expensive, and (b) it wouldn't really work, since if for example the slice got sorted, the original slice would be left alone.
Here's the question in the golang FAQ: http://golang.org/doc/faq#convert_slice_of_interface
Here's a more detailed explanation about slices of interfaces from the go wiki which explains better than I just did. https://code.google.com/p/go-wiki/wiki/InterfaceSlice