I am in Go, working with reflection. Imagine the presentation of the fragment. I have the following:
slice := reflect.MakeSlice(typ, len, cap)
If I want to get the ith value from slice , it's simple:
v := slice.Index(i)
However, I cannot find a way to set the i-th value. reflect.Value has many setter methods, for example, if I have a map, m , the following is possible:
m.SetMapIndex(key, value)
But there seems to be no equivalent for slices. I thought that perhaps the value returned from slice.Index(i) is actually a pointer, so calling v := slice.Index(i); v.Set(newV) v := slice.Index(i); v.Set(newV) will work? I'm not sure. Ideas?
reflection slice go
joshlf
source share