// reference to receiver
package main
import "fmt"
type Obj struct {
f string
}
func (o *Obj) Log() {
fmt.Println(o.f)
}
func main(){
o := Obj{}
o.f = "1"
o.Log()
call(o.Log)
}
func call(f func() ) {
f();
}// rewrite allocated memory
package main
func main() {
aaaa := "1"
bbbb := "2"
a := &aaaa
println(*a)
*a = bbbb
println(*a)
}
// invalid cast
package main
type Obj1 struct {f1 string; f2 string }
type Obj2 struct { f1 string }
func main(){
o1 := Obj1{
f1: "1",
f2: "2",
}
o2:= Obj2(o1) // cannot convert o1 (type Obj1) to type Obj2
// o2:= o1.(Obj2) // invalid type assertion: o1.(Obj2) (non-interface type Obj1 on left)
}