reflect.MakeSlice()
reflect.MakeSlice()
reflect.MakeSlice()
func MakeSlice(typ Type, len, cap int) Value
typreflect.Typelencap
reflect.Value
reflect.MakeSlice()
reflect.MakeSlice()
首先,我们需要导入 reflect 包:
import "reflect"
sliceType
sliceType := reflect.SliceOf(reflect.TypeOf(int(0)))
reflect.SliceOf()reflect.Typereflect.Type
reflect.MakeSlice()
sliceValue := reflect.MakeSlice(sliceType, 5, 10)
sliceValue.Interface()reflect.Valueinterface{}[]int