On Tuesday, 20 June 2017 06:52:58 UTC+2, Will Hawkins wrote: > > I know that there is a difference between interface values and dynamic > types and dynamic values. Is it possible that the documentation about the > %T is misleading? Should it be more specific that it returns the variable's > "dynamic type." > [...] > Should the documentation for %T be updated to say that it prints the > variable's dynamic type? >
Well, no. Look at fmt.Printf: It take a format string and a bunch of interface{} values to be printed. If %T would print the static type it always would print interface{}. To be useful Printf has too look inside it's arguments and inside is a HelloInt. The HelloListen basically gets lost while repacking the actual HelloInt into the empty interface{} of Printf's arguments. So all is fine, all is consistent and no documentation is misleading. It is just that fmt.Printf is not a magical function working outside of the type system. Any argument you supply is assigned to an empty interface. This is how argument passing in Go works. You might try: var empty interface{} empty = hellolisten fmt.Printf("empty: %T\n", empty) which makes this repacking into an interface{} explicit and now it is obvious that it will print main.HelloInt. V. -- 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. For more options, visit https://groups.google.com/d/optout.