On Sun, Jan 5, 2020 at 5:29 PM Ian Lance Taylor <i...@golang.org> wrote: > > On Sun, Jan 5, 2020 at 8:23 AM Manlio Perillo <manlio.peri...@gmail.com> > wrote: > > >> [...] > > I decided to run a simple test > > https://play.golang.org/p/QAX92NQDqO4. > > > > [...] > > > > The question is: why reflect.Type.String() returns `<nil>` instead of > > `interface{}` ? > > Is the example printing the static or the dynamic type? > > https://blog.golang.org/laws-of-reflection > > The reflect package takes value of type interface{}, so passing a > value of type interface{} and passing a value of type *interface{} > acts differently. > > Ian
Right, thanks. I was probably assuming TypeOf to be a generic function. I wrote another test https://play.golang.org/p/hoTAnijCfg1. Now it is clear why the first entry can only print nil for the type and <invalid reflect.Value> for the value. However printf %v verb prints nil for both an empty interface and an interface with a dynamic value of nil: https://play.golang.org/p/m_WfR2SPWQ3 Can this cause confusion? Thanks Manlio Perillo -- 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/CAAToxAGxQ_yXTUK-Jvw1eK8zwGnwXUXk7rCtB89XsCKNc_mpKg%40mail.gmail.com.