2017年5月6日
摘要: package main; import ( "fmt" "reflect" ) //反射refection //反射使用TypeOf和ValueOf函数从接口中获取目标对象信息 //反射会将匿名字段作为独立字段 type A struct { id int; name string; age int; } type B struct { A height int; ... 阅读全文
posted @ 2017-05-06 15:27 怀素真 阅读(471) 评论(0) 推荐(0) 编辑
摘要: package main; import "fmt" //接口interface //接口是一个或多个方法签名的集合 //只要某个类型拥有该接口的所有方法签名,即算实现该接口。 //接口只有方法声明,没有实现,没有数据字段 //接口可以匿名嵌入其它接口,或嵌入到结构中。 //GO语言中的所有类型都实现了空接口 type Empty interface { } type Inf inter... 阅读全文
posted @ 2017-05-06 11:39 怀素真 阅读(465) 评论(0) 推荐(0) 编辑
摘要: package main; import "fmt" //重新定义一个类型 //为该INT类型扩展方法 type INT int; type A struct { name string; } type B struct { name string; } func main() { a := A{}; a.Print(); //指针传递 a.Print2(); fmt.... 阅读全文
posted @ 2017-05-06 10:22 怀素真 阅读(437) 评论(0) 推荐(0) 编辑