Unclear about type assertion in pointer example

master
Patrick Mylund Nielsen 13 years ago
parent c6060554ee
commit 88b75b4791

@ -61,13 +61,13 @@ Usage:
c.Set("foo", foo, 0) c.Set("foo", foo, 0)
... ...
x, _ := c.Get("foo") x, _ := c.Get("foo")
foo := x.(MyStruct) foo := x.(*MyStruct)
fmt.Println(foo.Num) fmt.Println(foo.Num)
... ...
foo.Num++ foo.Num++
... ...
x, _ := c.Get("foo") x, _ := c.Get("foo")
foo := x.(MyStruct) foo := x.(*MyStruct)
foo.Println(foo.Num) foo.Println(foo.Num)
// will print: // will print:

@ -72,13 +72,13 @@ import (
// c.Set("foo", foo, 0) // c.Set("foo", foo, 0)
// ... // ...
// x, _ := c.Get("foo") // x, _ := c.Get("foo")
// foo := x.(MyStruct) // foo := x.(*MyStruct)
// fmt.Println(foo.Num) // fmt.Println(foo.Num)
// ... // ...
// foo.Num++ // foo.Num++
// ... // ...
// x, _ := c.Get("foo") // x, _ := c.Get("foo")
// foo := x.(MyStruct) // foo := x.(*MyStruct)
// foo.Println(foo.Num) // foo.Println(foo.Num)
// //
// will print: // will print:

Loading…
Cancel
Save