硬核——你真的搞定Golang接口了么

在此之前我还想简单阐述一下Go的类型系统 类型系统 首先我们要知道在Go中,这些属于内置类型: 1 2 3 4 5 6 7 8 9 10 bool int(32 or 64), int8, int16, int32, int64 uint(32 or 64), uint8(byte), uint16, uint32, uint64 float32, float64 string complex64, complex128 array -- 固定长度的数组 slice -- 序列数组 map -- 映射 chan -- 管道 当然还有自定义类型,比如: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // custom type based on int type T int // that is different from the one below // type T = int // that just a alias for T, it's type is still int // struct type T struct { name string } // interface type T interface { Name() string } Go不允许为内置类型添加方法,同时接口类型是无效的方法接收者。 ...

March 16, 2025 · 4 min · 807 words · Whitea