我有
type DocId int
func foo(documents []String) {
for i := range documents {
id := DocId(i)
...
}
}
如何去掉显式转换行?DocIds应该是用于索引单个文档的类型。
我想要的更像是:
func foo(documents []String) {
for id := range documents {
... // id gets used as the DocId that it damn well *IS*
}
}
当我试图使用来自range的id作为DocId时,它会给我“无效操作:...(类型不匹配int和DocId)”,即使DocId是一个int。