Example:
package main import ( "fmt" ) type A interface { Foo() } type B struct{} func (b *B) Foo() { // do smth... } func foo(b []*B) []A { return b // cannot use b (type []*B) as type []A in return argument } func main() { b := make([]*B, 10) a := foo(b) fmt.Println(a) } Interface A is fully satisfied with type *B , then why can not I return from function []*B as []A , and even explicit type conversion does not save? Where is my polymorphism? And is there any way to turn []*B into []A , except
aa := make([]A, 0, len(b)) for _, v := range b { aa = append(aa, v) }