golang 使用 iota
iota是golang语言的常量计数器,只能在常量的表达式中使用。 iota在const关键字出现时将被重置为0(const内部的第一行之前),const中每新增一行常量声明将使iota计数一次(iota可理解为const语句块中的行索引)。 使用iota能简化定义,在定义枚举时很有用。 举例如下: 1、iota只能在常量的表达式中使用。 fmt.Println(iota) 编译错误: undefined: iota 2、每次 const 出现时,都会让 iota 初始化为0. const a = iota // a=0 const ( b = iota //b=0 c //c=1 ) 3、自定义类型 自增长常量经常包含一个自定义枚举类型,允许你依靠编译器完成自增设置。 type Stere...阅读全文