func main() {
t := test // 如果这里改成 t:=new(test)就可以执行了
t.Name = "ACE"
t.test()
}
type test struct {
Name string
}
func (this test) test() {
fmt.Println(this.Name)
}
为什么这样写会报错?
command-line-arguments
./main.go:14: type test is not an expression
是因为没有实例化的原因么?如果不用new(不实例化), 怎么直接能调用到test?
这样就可以了,初始化一个对象是用 xxx{}