Skip to content

Instantly share code, notes, and snippets.

@yanjinbin
Last active November 27, 2017 10:35
Show Gist options
  • Save yanjinbin/b9ef58e62e9189e394d6abf5e24ddbfa to your computer and use it in GitHub Desktop.
Save yanjinbin/b9ef58e62e9189e394d6abf5e24ddbfa to your computer and use it in GitHub Desktop.
什么鬼.....
import (
"fmt"
)
type sport interface {
run() string
}
type Student struct {
age int
name string
ptrErr *sport
valueErr sport
}
type children struct {
name string
}
func (child *children) run() string {
return child.name + "is running"
}
func Foo_confuse() {
sport := new(sport)
fmt.Println(sport)
}
func Foo_TypeEmbedded() {
// 嵌入类型的不同 一个指针
student := &Student{
age: 11,
name: "嘻嘻哈哈",
ptrErr: new(sport),
// valueErr: new(children),// 可以 √
// 不可以 报错 cannot use new(sport) (type *sport) as type sport in field value:
//*sport is pointer to interface, not interface
valueErr:new(sport),
//报错 invalid pointer type *sport for composite literal
// valueErr:&sport{},
}
fmt.Println(student)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment