type分三类golang
自声明类型,分两种:c#
var Age int // 类型定义 var Int = int // 类型别名
类型定义,type: 一人千面post
底层类型,每个type都有其底层类型,1和2类的底层类型都是其自己,3的底层类型视状况而定。指针
type ( A1 = string A2 = A1 ) type ( B1 string B2 B1 B3 []B1 B4 B3 )
A1,A2,B1,B2的底层类型都是string,B3,B4的底层类型都是[]B1code
接口类型(interface type),推荐看Go接口深刻解析继承
interface {}
,空接口能够用来作泛型。type ReadWriter interface { Read(b Buffer) int Write(b Buffer) int } type File interface { ReadWriter Close() }
结构体类型,结构体是命名元素的序列,咱们称这些命名元素为字段,每一个字段都有名字(name)和类型(type)。非空字段的名字必须惟一,字段能够显式或者隐式(一个字段只有type而没有名字)的指定。接口
typt T struct { name string } type T1 struct { value int // 正常字段 int // 嵌入字段:int类型 *T // 嵌入字段:指向类型T的指针类型 }