如果你只是想要的类型,即使片是零,你可以使用像这样:
func value(m interface{}) reflect.Type { t := reflect.Indirect(reflect.ValueOf(m)).Type() if t.Kind() == reflect.Slice || t.Kind() == reflect.Array { t = t.Elem() if t.Kind() == reflect.Ptr { t = t.Elem() } return t } return t}关于
Type.Elem(),来自http://golang.org/pkg/reflect/#Type:
// Elem返回类型的元素类型。
//如果类型的Kind不是Array,Chan,Map,Ptr或Slice,则会出现恐慌。
// 编辑 更新了该函数,使其也适用于切片指针。



