💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
~~~ type Person struct { name string age int gender byte } func (p Person) getInfoValue() { fmt.Printf("%p %v\n", &p, p) } func (p *Person) getInfoPointer() { fmt.Printf("%p %v\n", &p, p) } func main() { p := Person{"jack",10,1} p.getInfoValue() //传统调用方式 pFunc := p.getInfoValue //这个就是方法值,调用函数时无需再传递接收者,隐藏了接收者. 等价于p.getInfoValue() pFunc() //方法表达式 f1 := (*Person).getInfoPointer f1(&p) //显示的把接收者传递过去 ===>p.getInfoPointer() f2 := (Person).getInfoValue f2(p) } ~~~ ~~~ 0xc42000a060 {jack 10 1} 0xc42000a0a0 {jack 10 1} 0xc42009a018 &{jack 10 1} 0xc4200a4060 {jack 10 1} ~~~