package mainimport "fmt"type person struct { name string age int8 gender string lastWord string}func New() *person { return &person{}}func (p *person) say(w string) { fmt.Printf("%s says %s \n", p.name, w) p.lastWord = w}func main() { //初始化一个struct 的几种方法 //new关键字 var liLei *person = new(person) liLei.name = "li Lei" liLei.say("hello") //使用&T{...}创建struct var hanMeiMei = &person{ "Han MeiMei", 11, "female", ""} hanMeiMei.say("good!") // := 赋值 lily := &person{ "lily", 10, "female", ""} lily.say("wellcome")}