|
|
|
|
|
by 9rx
323 days ago
|
|
> And passing pointers to strings rather than strings, hmmm. Are you referring to the "URL" example? That isn't a case of passing pointers to strings, that is passing a URL (fmt.Stringer) where the String method has a pointer receiver. To demonstrate why the pointer would be needed in that case, consider: type URL struct{}
func (*URL) String() string { return "https://..." }
func print(v any) { fmt.Println(v.(fmt.Stringer).String()) }
func main() {
print(&URL{}) // ok
print(URL{}) // panic
}
|
|