Last active
November 27, 2017 10:35
-
-
Save yanjinbin/b9ef58e62e9189e394d6abf5e24ddbfa to your computer and use it in GitHub Desktop.
什么鬼.....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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