students :=append( make([]Student,0,3),
Student{"aaa",1,9},
Student{"bbb",2,6},
Student{"ccc",4,10})
tar := make([] reflect.Value,0,3)
for _,s := range students {
c := reflect.ValueOf(&s).Elem()
fmt.Println(c)
tar = append(tar,c)
for _,e := range tar {
fmt.Println(e,"===")
}
}
for _,e := range tar {
fmt.Println(e)
}
就3个student对象,每个都不一样,我取每个的反射append到一个数组里,到最后数组里是3最后一个student的反射对象
就是每次往数组添加元素都会把之前以存在的对象都覆盖成这次添加的。student对象就没事,就反射对象会这样
有疑问加站长微信联系(非本文作者)