是否可以用var定义1个结构体?

taatcc · · 1518 次点击
go的匿名还真多,匿名结构体,匿名接口,匿名类型,请问还有哪些匿名?想学习下,按你的提示写了个匿名接口,觉得挺方便 ```go package main import "fmt" var Animal interface { showColor() } type Cat struct{ color string } func (cat Cat) showColor(){ cat.color="red" fmt.Println(cat.color) } func main() { Animal=new(Cat) Animal.showColor() //输出:red } ```
#13
更多评论
这个应该是定义了匿名struct类型的Book变量
#1
只不过形式和type有很像
#2