Using reflect to update value by reference when argument is not a pointer in go
问题 I've had difficulty learning the basics of reflect, pointers and interface in go, so here's another entry level question I can't seem to figure out. This code does what I want it to do - I'm using reflect to add another record to a slice that's typed as an interface. package main import ( "reflect" "log" ) type Person struct { Name string } func Add(slice interface{}) { s := reflect.ValueOf(slice).Elem() // in my actual code, p is declared via the use of reflect.New([Type]) p := Person{Name: