Unclear about type assertion in pointer example
This commit is contained in:
parent
c6060554ee
commit
88b75b4791
4
README
4
README
|
@ -61,13 +61,13 @@ Usage:
|
|||
c.Set("foo", foo, 0)
|
||||
...
|
||||
x, _ := c.Get("foo")
|
||||
foo := x.(MyStruct)
|
||||
foo := x.(*MyStruct)
|
||||
fmt.Println(foo.Num)
|
||||
...
|
||||
foo.Num++
|
||||
...
|
||||
x, _ := c.Get("foo")
|
||||
foo := x.(MyStruct)
|
||||
foo := x.(*MyStruct)
|
||||
foo.Println(foo.Num)
|
||||
|
||||
// will print:
|
||||
|
|
4
cache.go
4
cache.go
|
@ -72,13 +72,13 @@ import (
|
|||
// c.Set("foo", foo, 0)
|
||||
// ...
|
||||
// x, _ := c.Get("foo")
|
||||
// foo := x.(MyStruct)
|
||||
// foo := x.(*MyStruct)
|
||||
// fmt.Println(foo.Num)
|
||||
// ...
|
||||
// foo.Num++
|
||||
// ...
|
||||
// x, _ := c.Get("foo")
|
||||
// foo := x.(MyStruct)
|
||||
// foo := x.(*MyStruct)
|
||||
// foo.Println(foo.Num)
|
||||
//
|
||||
// will print:
|
||||
|
|
Loading…
Reference in New Issue