```golang
package main
type Entity interface {
Say() string
}
type Cat struct{}
func (c Cat) Say() string {
return "我是一只猫"
}
type Union struct {
Mem []Entity
}
func main() {
var cats []Cat
cats = append(cats, Cat{})
cats = append(cats, Cat{})
cats = append(cats, Cat{})
u := Union{
Mem: cats,
}
}
```
如上代码,声明一个名为```Entity```的```interface```,包含一个方法```Say() string```,再声明一个名为```Cat```的```struct```实现该方法,我把```Union```的```Mem```属性声明为```[]Entity```类型,但是对该字段赋值时会报错如下:
```shell
: cannot use cats (type []Cat) as type []Entity in field value
```
求大佬指教,该怎么调整???
有疑问加站长微信联系(非本文作者)