我想将reflect.Kind作为实现接口的类型的reflect.Interface,但其实现基于原始类型:type id string
对此问题的另一种答案可能是如何在调用 Kind() 时获取返回reflect.Interfaces 的任何类型的reflect.Type。
这是Go Playground上的完整示例:
type ID interface {
myid()
}
type id string
func (id) myid() {}
func main() {
id := ID(id("test"))
fmt.Println(id)
fmt.Println(reflect.TypeOf(id))
// How to get the kind to return "reflect.Interface" from the var "id"?
fmt.Println(reflect.TypeOf(id).Kind())
}
Run Code Online (Sandbox Code Playgroud)