Skip to content

Instantly share code, notes, and snippets.

@khrm
Created June 14, 2016 11:28
Show Gist options
  • Save khrm/26e4e71ec08fac6af303b0a632a52197 to your computer and use it in GitHub Desktop.
Save khrm/26e4e71ec08fac6af303b0a632a52197 to your computer and use it in GitHub Desktop.
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