On Thu, Aug 17, 2023 at 10:02 AM Hu Jian <hujia...@gmail.com> wrote: > > I'm curious why reflect.Type is defined as an interface, but reflect.Value is > defined as a struct? I don't see any other implementation of the reflect.Type > interface.
reflect.Value is an ordinary struct. The reflect.Type interface is really implemented by several different types, each of which begins with the same struct but is then followed by type-specific information. On tip this is abi.PointerType, abi.StructType, and so forth. That data structure can in turn be followed by abi.UncommonType. So we have several possible implementations for reflect.Type, although they all exist in the reflect package. Also reflect.Value is small enough to pass around as a value, rather than taking a pointer and sometimes forcing the Value into the heap There's no reason to do that for reflect.Type, as we are normally using pointers to data structures created by the compiler, not data structures in the heap. I think it's true that we could today push everything into a single struct, and do all the pointer conversions behind the scenes, but it wouldn't help much, and we can't make that change today anyhow. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWUvj5kkw6wUeMneGyEqh8MRZXO3CLd5Oz6rSY_z%2BhYuQ%40mail.gmail.com.