go - Embed channel in struct -
go - Embed channel in struct -
how embed channel in struct in go?
why inconsistency between map syntax:
var m map[string]int and channel,
var m chan int ?
to clarify, in go possible embed type in type. embedder type gains access methods defined on embedded type, possible refer embedded type explicitly name of type. therefore, inconsistency between map type declaration , channel type declaration confusing refer embedded channel type.
the problem embedding allows benefit methods embedded type (as mentioned in "embedding instead of inheritance in go")
and channel, map, unnamed type (specified using type literal, composes new type existing types.). doesn't have methods of own, or exported fields, wouldn't go far embedding channel type within struct {}.
you have error message similar 1 in example:
func (x chan int) m2() {} invalid receiver type chan int (chan int unnamed type) if embedding channel type within struct type worked, unnamed type able deed receiver methods, doesn't seem allowed language in first place.
go
Comments
Post a Comment