Last active
February 5, 2019 17:03
-
-
Save betandr/fced026d8ac63184e7098eb9b0909c5b to your computer and use it in GitHub Desktop.
Pointer vs Named Receivers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type SomeThing struct { | |
Msg string | |
} | |
func (t SomeThing) SomeNamedReciever(msg string) { | |
t.Msg = msg | |
fmt.Println(t.Msg) // ¡Hola Mundo! | |
} | |
func (t *SomeThing) SomePointerReciever(msg string) { | |
t.Msg = msg | |
fmt.Println(t.Msg) // こんにちは世界 | |
} | |
func main() { | |
t := new(SomeThing) | |
t.Msg = "Hello, World!" | |
fmt.Println(t.Msg) // Hello, World! | |
t.SomeNamedReciever("¡Hola Mundo!") | |
fmt.Println(t.Msg) // Hello, World! | |
t.SomePointerReciever("こんにちは世界") | |
fmt.Println(t.Msg) // こんにちは世界 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment