How can I instance an array with a given type?
I get the type this way:
type := reflect.ValueOf(obj)
But I don't know how to get an instance of an array with this type
How can I instance an array with a given type?
I get the type this way:
type := reflect.ValueOf(obj)
But I don't know how to get an instance of an array with this type
收起
Use reflect.MakeSlice for that:
type := reflect.ValueOf(obj)
reflectSlice := reflect.MakeSlice(type, sliceLength, sliceCapacity)
报告相同问题?