类别概述
类型表示了一系列带有操作符号或者方法的数值。类型通常通过它的 类型名字 来表示, 如果它没有自己的名字的话,或者说是引用了某一种数据类型,那就代表它是一种在已有数据类型之上的复合类型。
Type = [TypeName](https://golang.org/ref/spec#TypeName) | [TypeLit](https://golang.org/ref/spec#TypeLit) | "(" [Type](https://golang.org/ref/spec#Type) ")" .
TypeName = [identifier](https://golang.org/ref/spec#identifier) | [QualifiedIdent](https://golang.org/ref/spec#QualifiedIdent) .
TypeLit = [ArrayType](https://golang.org/ref/spec#ArrayType) | [StructType](https://golang.org/ref/spec#StructType) | [PointerType](https://golang.org/ref/spec#PointerType) | [FunctionType](https://golang.org/ref/spec#FunctionType) | [InterfaceType](https://golang.org/ref/spec#InterfaceType) |
[SliceType](https://golang.org/ref/spec#SliceType) | [MapType](https://golang.org/ref/spec#MapType) | [ChannelType](https://golang.org/ref/spec#ChannelType) .
Go 语言 预先声明 了一些数据类型, 其他的在这里能找到介绍 类型声明。 复合类型—array, struct, pointer, function, interface, slice, map, 和 channel 类型 — 可以通过预定义类型组合声明的。
每种类型 T 都有自己的 基础类型: 如果 T 预声明的类型之一,比如 boolean, numeric, 或者 string 类型, 或其他普通类型, 对应的基础类型就是 T 自己。 否则, T 的基础类型就是 T 所引用的数据类型,请参考 类型声明。
type (
A1 = string
A2 = A1
)
type (
B1 string
B2 B1
B3 []B1
B4 B3
)
数据类型是string比如, A1, A2, B1, 和 B2, 而数据类型是 []B1 的就有B3和 B4 。
本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。
Go 语言规范
关于 LearnKu