TypeOf without an instance and passing result to a func
Yes, it’s possible. The trick is to start from a pointer to the type (whose value can be a typed nil, that’s perfectly OK), and then use Type.Elem() to get the reflect.Type descriptor of the pointed type (the base type). See some examples: t := reflect.TypeOf((*int)(nil)).Elem() fmt.Println(t) t = reflect.TypeOf((*http.Request)(nil)).Elem() fmt.Println(t) t = reflect.TypeOf((*os.File)(nil)).Elem() fmt.Println(t) … Read more