type Call interface {标签:En,return,string,接口,循环,Call,func,go,String From: https://www.cnblogs.com/cheyunhua/p/17488310.html
String() string
}
type Cn struct {
}
type En struct {
}
func Newcn() Call {
return &Cn{}
}
func (c *Cn) String() string {
b, _ := json.Marshal(c)
fmt.Println(b)
return string(b)
}
func Newen() Call {
return &En{}
}
func (e *En) String() string {
b, _ := json.Marshal(e)
fmt.Println("test")
return string(b)
}
func main() {
var calls []Call = []Call{Newcn(), Newen()}
for _, v := range calls {
v.String()
}
}