Created
June 14, 2016 11:28
-
-
Save khrm/26e4e71ec08fac6af303b0a632a52197 to your computer and use it in GitHub Desktop.
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 Person struct { | |
name string | |
age int | |
} | |
func main() { | |
p := &Person{"test", 11} | |
// how to build an interface{} object from person struct? | |
// what is the cost? the field need copy? | |
var v interface{} | |
v = p | |
p.age=13 | |
l := v.(*Person) | |
l.age=17 | |
fmt.Println(v,p,l) | |
} | |
//Output | |
&{test 17} &{test 17} &{test 17} | |
/////////////// | |
package main | |
import ( | |
"fmt" | |
) | |
type Person struct { | |
name string | |
age int | |
} | |
func main() { | |
p := Person{"test", 11} | |
// how to build an interface{} object from person struct? | |
// what is the cost? the field need copy? | |
var v interface{} | |
v = p | |
p.age=13 | |
l := v.(Person) | |
l.age=17 | |
fmt.Println(v,p,l) | |
} | |
//Output | |
{test 11} {test 13} {test 17} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment