Running the code below will result in a compilation error:
cannot use authors (type []Person) as type []Namer in return argument
Why can't Go compile it?
type Namer interface {
Name() string
}
type Person struct {
name string
}
func (r Person) Name() string {
return r.name
}
func Authors() []Namer {
// One or the other is used - both are not good:
authors := make([]Person, 10)
var authors []Person
...
return authors
Declaring authors as authors := make([]Namer, 10) or var authors []Namer would be fine, but I can't see why the compiler cannot infer that Person is Namer.