Golang的iota的特性

Golang的iota的特性:

1. iota在每个ConstBlock中自动归0.

2. iota在每个ConstSpec后自动增1.

换言之: iota是ConstBlock中ConstSpec的下标.

例如:

const (

item0 = 1

item1 = 1

item2 = 1

item3 = 1

item4 = 1

item5 = 1

item6 = iota

)
func main() { fmt.Println(item0, item1, item5, item6)}
输出结果:

1 1 1 6

可见, iota就是ConstBlock中ConstSpec的下标. 所以item6的值是6, 而不是0.

posted @ 2016-09-07 13:32  zolo®  阅读(215)  评论(0编辑  收藏  举报