On Wed, Mar 9, 2022 at 7:18 PM Nikhilesh Susarla <nikhilesh1...@gmail.com> wrote:
> In https://go.dev/doc/effective_go#printing > I saw an example for printing our custom string output for the type. > The code below is from docs. > func (t *T) String() string { > return fmt.Sprintf("%d/%g/%q", t.a, t.b, t.c) > } > fmt.Printf("%v\n", t) > > > But rather the statement should be this right? fmt.Printf("%v\n", > t.String()) > Am I missing something? > An object with a String() method causes that method to be used wherever a string is desired. This includes the `%s` and `%v` formatting verbs. From the paragraph preceding the example: > If you want to control the default format for a custom type, all that's required is to define a method with the signature String() string on the type. -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- 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/CABx2%3DD9FeOzh9Dsv%2BMt%2BhMVfA%2BeQU_M_7zCNbMnsQDkLJT8EnQ%40mail.gmail.com.