Last active
August 29, 2015 14:03
-
-
Save jescalan/706a5372bdacb08870c6 to your computer and use it in GitHub Desktop.
Is there any reason to ever use the new keyword 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
package main | |
import "fmt" | |
type Vertex struct { | |
X, Y int | |
} | |
func main() { | |
v := new(Vertex) | |
fmt.Println(v) // &{0, 0} | |
v.X, v.Y = 11, 9 | |
fmt.Println(v) // &{11, 9} | |
t := &Vertex{} | |
fmt.Println(t) // &{0, 0} | |
t.X, t.Y = 11, 9 | |
fmt.Println(t) // &{11, 9} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment