我想在golang中使用名字创建数组,但是遇到了一些错误。 下面是我的代码: package main
import (
"fmt"
"reflect"
)
type My struct{
Name string
Id int
}
func main() {
my := &My{}
myType := reflect.TypeOf(my)
fmt.Println(myType)
//v := reflect.New(myType).Elem().Interface()
// I want to make array with My
//a := make([](myType.(type),0) //can compile
//a := make([]v.(type),0) ////can compile
fmt.Println(a)
}
reflect.Append
和AppendSlice
函数。 - Gustavo Niemeyer