案例1:
func main() { var str string = "tom" //ok fs := reflect.ValueOf(str) //ok fs.SetString("jack") //error fmt.Printf("%v\n", str) }
输出报错:
修改如下:
func main() { var str string = "tom" fs := reflect.ValueOf(&str) fs.Elem().SetString("jack") fmt.Printf("%v\n", str) }
输出:
标签:反射,fs,fmt,ValueOf,str,tom,var From: https://www.cnblogs.com/wuchangblog/p/16728793.html