您指向结构的指针应实现该接口。这样,您可以修改其字段。
查看我如何修改您的代码,以使其按预期工作:
package mainimport ( "fmt")type IFace interface { SetSomeField(newValue string) GetSomeField() string}type Implementation struct { someField string}func (i *Implementation) GetSomeField() string { return i.someField}func (i *Implementation) SetSomeField(newValue string) { i.someField = newValue}func Create() *Implementation { return &Implementation{someField: "Hello"}}func main() { var a IFace a = Create() a.SetSomeField("World") fmt.Println(a.GetSomeField())}


