On Sun, Jan 5, 2020 at 8:23 AM Manlio Perillo <manlio.peri...@gmail.com> wrote:
>
> I'm re-reading the Go Language Specification, and at 
> https://golang.org/ref/spec#Variables I found this example:
>
>   var x interface{} // x is nil and has static type interface{}
>   var v *T               // v has value nil, static type *T
>   x = 42                 // x has value 42 and dynamic type int
>   x = v                   // x has value (*T)(nil) and dynamic type *T
>
> Since the first comment is different for the others (`x is nil` against `x 
> has value`) I decided to run a simple test
> https://play.golang.org/p/QAX92NQDqO4.  It has an additional entry:
>   var z *interface{}
>
>
> The output of the first and last line is
>
> x is nil and has static type interface{}
> <invalid reflect.Value> <nil>
>
> z is nil and has static type *interface{}
> <nil> *interface {}
>
>
> 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

-- 
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/CAOyqgcXTXeE2PwNPC07_6qow4%2BK8-WpU8pkWEUTEQHDa3cGtMg%40mail.gmail.com.

Reply via email to