Last active
May 29, 2018 14:59
-
-
Save bonifaido/cf966d2c41521ef95fcdd541b04c0c46 to your computer and use it in GitHub Desktop.
Difference between taking something by value or by pointer in Go
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
&main.Something{} | |
(*interface {})(0xc42000e1e0) |
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{} | |
func receiverByPointer(p interface{}) { | |
fmt.Printf("%#v\n", p) | |
} | |
func receiverByValue(p interface{}) { | |
fmt.Printf("%#v\n", &p) | |
} | |
func main() { | |
receiverByPointer(&Something{}) | |
receiverByValue(Something{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment