mirror of
https://github.com/golang/go
synced 2024-11-21 17:04:42 -07:00
effective go: explain about values/pointers in String() example
Fixes #1796. R=rsc, r2, niemeyer CC=golang-dev https://golang.org/cl/4539049
This commit is contained in:
parent
55d43f0ce8
commit
89c59bc6f6
@ -1489,6 +1489,12 @@ to print in the format
|
||||
7/-2.35/"abc\tdef"
|
||||
</pre>
|
||||
<p>
|
||||
(If you need to print <em>values</em> of type <code>T</code> as well as pointers to <code>T</code>,
|
||||
the receiver for <code>String</code> must be of value type; this example used a pointer because
|
||||
that's more efficient and idiomatic for struct types.
|
||||
See the section below on <a href="#pointers_vs_values">pointers vs. value receivers</a> for more information.)
|
||||
</p>
|
||||
<p>
|
||||
Our <code>String()</code> method is able to call <code>Sprintf</code> because the
|
||||
print routines are fully reentrant and can be used recursively.
|
||||
We can even go one step further and pass a print routine's arguments directly to another such routine.
|
||||
|
Loading…
Reference in New Issue
Block a user