result *[]xxx
1. 判断接口是否为空
2. 构造新指针类型,并赋值空切片
if reflect.ValueOf(result).Elem().IsNil() { resultType := reflect.TypeOf(result).Elem() t2 := reflect.New(resultType) t3 := t2.Elem() t3.Set(reflect.MakeSlice(resultType, 0, 0)) List = t2.Interface() _, ok := t2.Interface().(*[]xxx ) fmt.Printf("ok: %v\n", ok) }
标签:reflect,ok,t2,Elem,golang,resultType,重塑,result,指针 From: https://www.cnblogs.com/zjchao/p/17562603.html